Problem 7 "10001st prime number"
When the six prime numbers are arranged from the smallest, they are 2, 3, 5, 7, 11, 13 and the sixth prime number is 13. 1000 Find the first prime number.
Python
n = 10001
def generate_primes(n):
primes = [2]
i = 3
while len(primes) < n:
for p in primes:
if i % p == 0:
break;
else:
primes += [i]
i += 2
return primes
primes = generate_primes(n)
result = primes[-1]
print result
print result == 104743
print len(primes)
result
104743
True
10001
Recommended Posts