Created
August 17, 2009 19:26
-
-
Save akrito/169320 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from math import sqrt | |
# Set up the array | |
m = 2000000 | |
nums = range(m) | |
nums[1] = 0 | |
i = 0 | |
while i**2 < m: | |
if nums[i] == 0: | |
i += 1 | |
continue | |
# The next non-zero should be prime | |
p = nums[i] | |
# Zero out all the multiples of p, starting at the square (optimization) | |
j = p | |
while j * p < m: | |
nums[j * p] = 0 | |
j += 1 | |
i += 1 | |
t = 0 | |
for p in nums: | |
t += p | |
print t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment