Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question