Skip to content

Instantly share code, notes, and snippets.



Created Jun 25, 2013
What would you like to do?
Sieve of Eratosthenes
def gen_prime_sieve(n):
# Implementation uses the Sieve of Eratosthenes
# Optimized code from:
a = [True] * n
a[0] = a[1] = False
for (i, isprime) in enumerate(a):
if isprime:
yield i
for n in xrange(i*i, n, i):
a[n] = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment