Created
December 14, 2015 15:31
-
-
Save seriusokhatsky/053fcd62e58d9bd04840 to your computer and use it in GitHub Desktop.
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
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