Project Euler #7: 10001st prime

  • + 0 comments
    import math
    def sieve_of_eratosthenes(limit):
        is_prime = [True] * (limit + 1)
        p = 2
        while p * p <= limit:
            if is_prime[p]:
                for i in range(p * p, limit + 1, p):
                    is_prime[i] = False
            p += 1
        prime_numbers = [p for p in range(2, limit + 1) if is_prime[p]]
        return prime_numbers
    
    
    t = int(input())
    for j in range(t):
        n = int(input())
        if n < 6:
            limit = 15
        else:
            limit = int(n * (math.log(n) + math.log(math.log(n))))  # returns a int(float)
    
        primes = sieve_of_eratosthenes(limit)
        print(primes[n - 1])