Skip to content

Instantly share code, notes, and snippets.

@seriusokhatsky
Created December 14, 2015 15:31
Show Gist options
  • Save seriusokhatsky/053fcd62e58d9bd04840 to your computer and use it in GitHub Desktop.
Save seriusokhatsky/053fcd62e58d9bd04840 to your computer and use it in GitHub Desktop.
import math
n = 2000000
def primesTo(lim):
primes = [2]
t = 0
sieve = [False] * lim
crosslim = int(math.sqrt(lim))
for i in range(3, lim, 2):
sieve[i] = True
for i in range(3, crosslim, 2):
if not sieve[i-1]: #hence prime
for k in range((i-1)*2+1,lim,i):
sieve[k] = True
for i in range(1, lim):
if not sieve[i]:
t = t + i + 1
print t
return t
primesTo(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment