Skip to content

Instantly share code, notes, and snippets.

@Zhangerr
Created July 8, 2013 07:21
Show Gist options
  • Save Zhangerr/5946825 to your computer and use it in GitHub Desktop.
Save Zhangerr/5946825 to your computer and use it in GitHub Desktop.
test sieve of eratosthenes
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