10001st prime
First read the problem description.
A simple Sieve of Eratosthenes.
import array
def primes_upto(N):
= array.array('B')
S 0 for x in range((N >> 3) + 1))
S.extend(def set_bit(i):
>>3] |= 1<<(i&7)
S[idef is_bit_set(i):
return S[i>>3]&(1<<(i&7))
= 2
p for p in range(p, N+1):
if not is_bit_set(p):
yield p
= 0
k while True:
= p*p + k*p
i if i > N:
break
set_bit(i)+= 1
k
next(p for i,p in enumerate(primes_upto(1_000_000)) if i+1==10001)
104743
Source code of the solution(s):