Created
January 19, 2014 12:00
-
-
Save sokrato/8503879 to your computer and use it in GitHub Desktop.
10001st prime. http://projecteuler.net/problem=7
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
#-*- coding: utf8 -*- | |
def isPrime(num, ps): | |
for i in ps: | |
if num%i == 0: | |
return False | |
if i**2 > num: | |
break | |
return True | |
def primes(total=10001): | |
ps = [2,3,5,7,11,13] | |
while total - len(ps) > 0: | |
tmp = ps[-1]+2 | |
while True: | |
if isPrime(tmp, ps): | |
ps.append(tmp) | |
break | |
else: | |
tmp += 2 | |
return ps[-1] | |
print primes(10001) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very fast!