Skip to content

Instantly share code, notes, and snippets.

@wrhall
Created November 5, 2013 03:55
Show Gist options
  • Save wrhall/7313630 to your computer and use it in GitHub Desktop.
Save wrhall/7313630 to your computer and use it in GitHub Desktop.
Sieve (quickly thrown together)
6 import math
7
8 def sieve(n):
9 a = range(n+1)
10 a[1] = 0
11 index = 0
12 while index < len(a):
13 if a[index] != 0:
14 increment = a[index]
15 for i in xrange(2*increment, len(a), increment):
16 a[i] = 0
17 index += 1
18 return a
19
20
21 print sum(sieve(2000000))
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment