Last active
October 22, 2016 01:39
-
-
Save BedirYilmaz/1bd2dab68dec1d1b1c094fb5ebaddb1e to your computer and use it in GitHub Desktop.
Find 10001 nth prime number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Special thanks to Ceyhan Yılmaz and cosinus | |
def nthPrime(n): | |
number = 3 | |
primemultiples = [] | |
primes = [] | |
primes.append(2) | |
prime = True | |
while (len(primes)<=n): | |
prime = True | |
if number in primemultiples: | |
prime = False | |
number +=2 | |
continue | |
for i in range (3, number): | |
if number%i == 0: | |
prime = False | |
break | |
if(prime): | |
multiple = number | |
while multiple <= n: | |
multiple *= 2 | |
primemultiples.append(multiple) | |
primes.append(number) | |
number += 2 | |
return primes[n-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment