We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
primes = [True]*(num+1)
primes[0] = False
primes[1] = False
for i in range(2, int(num**0.5)+1):
if primes[i]:
for j in range(i*i, num+1, i):
primes[j] = False
primes = [i for i in range(num+1) if primes[i]]
return primes
def nth_prime(n, precomputed_primes):
import math
if n <= len(precomputed_primes):
return precomputed_primes[n-1]
else:
limit = int(n*math.log(n)*1.5) if n > 5 else 15
Project Euler #7: 10001st prime
You are viewing a single comment's thread. Return to all comments →
python version of the answer
def prime_s(num):
def nth_prime(n, precomputed_primes): import math if n <= len(precomputed_primes): return precomputed_primes[n-1] else: limit = int(n*math.log(n)*1.5) if n > 5 else 15
precomputed_primes = prime_s(10**6) t = int(input().strip()) for a0 in range(t): n = int(input().strip())