Skip to content

Instantly share code, notes, and snippets.

@gennad
Created July 4, 2011 08:41
Show Gist options
  • Save gennad/1063078 to your computer and use it in GitHub Desktop.
Save gennad/1063078 to your computer and use it in GitHub Desktop.
Eratosthene's sieve
n = input("n = ")
a = range(n+1)
a[1] = 0
lst = []
i = 2
while i <= n:
if a[i] != 0:
lst.append(a[i])
for j in xrange(i, n+1, i):
a[j] = 0
i += 1
print lst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment