Skip to content

Instantly share code, notes, and snippets.

@jon
Created December 18, 2011 05:23
Show Gist options
  • Save jon/1492455 to your computer and use it in GitHub Desktop.
Save jon/1492455 to your computer and use it in GitHub Desktop.
from sys import argv
from math import sqrt
maxval = int(argv.pop())
x = [ True ] * maxval
x[0] = False
for n in xrange(1, int(sqrt(maxval + 1)), 2):
if x[n - 1]:
m = n ** 2
increment = 2 * n
while m <= maxval:
x[m - 1] = False
m += increment
primes = [ n for n in xrange(1, maxval + 1, 2) if x[n - 1] ]
print sum(primes) + 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment