Python Forum
calculate the 10001st prime number
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
calculate the 10001st prime number
#1
I'm learning python by following project euler. Q7 asks you to calculate the 10001st prime.

i did the following (in pseudocode):

def div(n): makes a list of all the divisors.
def prim(n): checks if n is prime by check the list of all divisors. If len(div(n)) == 2, 2 is prime.

then i asked the computer to find all primes from 1 to 100000 with the above functions:


------------------------------------
y = []  
m = 1 
while m < 100000:
  if prim(m) == True: y = y + [m]
  m = m + 1
------------------------------------

but of course, it was taking too long.

Is there an easier way of doing this?

What i'm doing now is: I'm calculating how many primes are there between 0k and 10k, then 10k to 20k, then 20k to 30k.... summing the quantities, and when it gets to 10001, i print the primes and look for it. but this is a terrible solution....
Reply


Messages In This Thread
calculate the 10001st prime number - by topologh - Mar-30-2018, 10:59 AM
RE: calculate the 10001st prime number - by Zatox11 - Mar-30-2018, 05:30 PM
RE: calculate the 10001st prime number - by Zatox11 - Mar-30-2018, 07:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to find the next prime number FirstBornAlbratross 8 5,217 Aug-14-2023, 01:16 PM
Last Post: deanhystad
  Calculate the multiple of a number pythonuser1 7 4,728 Mar-27-2020, 02:22 PM
Last Post: deanhystad
  Prime number code ryfoa6 3 3,047 Mar-21-2020, 12:23 AM
Last Post: ryfoa6
  Trouble interpreting prime number code ryfoa6 1 2,383 Mar-20-2020, 03:47 PM
Last Post: stullis
  Prime number Python homework mkrisz98 11 5,925 May-10-2019, 05:23 PM
Last Post: mkrisz98
  how to find a next prime number? iamyourfather 2 6,685 Oct-01-2017, 04:21 PM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020