Skip to content

Instantly share code, notes, and snippets.

@sokrato
Created January 19, 2014 12:00
Show Gist options
  • Save sokrato/8503879 to your computer and use it in GitHub Desktop.
Save sokrato/8503879 to your computer and use it in GitHub Desktop.
#-*- 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)
@sokrato
Copy link
Author

sokrato commented Jan 19, 2014

Very fast!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment