Created
July 8, 2013 07:21
-
-
Save Zhangerr/5946825 to your computer and use it in GitHub Desktop.
test sieve of eratosthenes
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
max = 10000000 | |
rm = max+1 | |
primes = range(0,rm) | |
primes[0]=-1 | |
primes[1]=-1 | |
p = 2 | |
pold = 2 | |
while 1: | |
#print p | |
i = 0 | |
while 1: | |
j = p * (p+i) | |
if j <= max: | |
primes[j] = -1 | |
# print j | |
else: | |
break | |
i+=1 | |
pold = p | |
if p**2>max: | |
break | |
for i in xrange(p+1,rm): | |
if primes[i] != -1: | |
# print i | |
p = primes[i] | |
break | |
# print p | |
if pold == p: | |
break | |
print filter(lambda g: g > 0,primes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment