A
A
alex_6432020-06-12 08:19:56
Python
alex_643, 2020-06-12 08:19:56

Efficient algorithm for finding the k-th prime number?

Hello! I need an efficient algorithm for finding the kth prime number in python. I tried to put a counter, but it turns out a lot of computational complexity. If there is an implementation with an erastofen sieve, please give it. Help me please!

def IsPrime(n):
    d = 2
    while d * d <= n and n % d != 0:
        d += 1
    return d * d > n
check = False
n = int(input())
i = 1
s = 0
numbers = []
while s < n:
    i += 1
    if IsPrime(i):
        numbers.append(i)
        s += 1
    else:
        continue
print(numbers[n - 1])

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2020-06-12
@phaggi

Help is coming

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question