Last active
October 22, 2016 19:48
-
-
Save BedirYilmaz/d0bffef11e0380b17c6ac9a2b74d5d7a to your computer and use it in GitHub Desktop.
Find the nth prime number
This file contains hidden or 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
def nthPrimeSqrt(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 | |
root = int(math.ceil(math.sqrt(number))) | |
for i in range (3, root): | |
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