Created
November 5, 2013 03:55
-
-
Save wrhall/7313630 to your computer and use it in GitHub Desktop.
Sieve (quickly thrown together)
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
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