Skip to content

Instantly share code, notes, and snippets.

@goyuninfo
Created May 26, 2014 03:03
Show Gist options
  • Save goyuninfo/90cd4c13f01f44712c64 to your computer and use it in GitHub Desktop.
Save goyuninfo/90cd4c13f01f44712c64 to your computer and use it in GitHub Desktop.
Problem 10. Sum all primes below N million
import math
def isPrime(n):
sqrt=int(math.sqrt(n))
for i in range(2,sqrt+1):
if n%i==0:
return 0
return 1
s=2+3
n=int((2000000-1)/6)
for i in range(1,n+1):
if isPrime(6*i-1):
s+=6*i-1
if isPrime(6*i+1):
s+=6*i+1
print(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment