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?
I have tried like this:
def isprime(num):
i=2
import math
while (int(math.sqrt(num))+1)>=i:
if num%i==0:
return False
i = i+1
return True
def findprime(n):
prime = 1
for i in range(3,n):
if isprime(i):
prime = prime+1
if prime == 10001:
return i
I am calling the findprime()
with a big integer. so Its loop through all the integer within the range and its take a lot of time to generate the output and sometime my python shell hanged because of the large input. Is there any smart way to do this?