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?

this solution just starts to divide by the prime numbers, but we do only for primes $<\sqrt{p}$ and use binary search to find the limit.


In [56]:
def find_n_th_prime(n):
    from math import sqrt
    from bisect import bisect_right
    primes = [2]
    i = 3

    while n != len(primes):
        ok = True
        for p in primes[:bisect_right(primes, sqrt(i))]:
            if i % p == 0:
                ok = False
                break
        if ok:
            primes.append(i)
        i += 1

    print('\n', len(primes), primes[-1:])
find_n_th_prime(n=10001)


 10001 [104743]

In [57]:
%timeit find_n_th_prime(n=10001)


 10001 [104743]

 10001 [104743]

 10001 [104743]

 10001 [104743]
1 loops, best of 3: 288 ms per loop