Euler Problem 7

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10,001st prime number?


In [1]:
MAX = 200000
index = 10001
sieve = [True] * MAX
prime_count = 0
for p in range(2, MAX):
    if sieve[p]:
        prime_count += 1
        if prime_count == index:
            print(p)
            break
        for n in range(p*p, MAX, p):
            sieve[n] = False


104743

The Sympy module makes this problem even easier.


In [2]:
from sympy import prime
print(prime(index))


104743

In [ ]: