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:
------------------------------------
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....
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....