Problem 10: Summation of Primes
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
# making a list of true/false prime indices is much faster than
# individually checking primality for every number
primes = [True]*2000000
for i in range(2, len(primes)//2+1):
for j in range(i*2, len(primes), i):
primes[j] = False
primes[0], primes[1] = False, False
print(sum([i for i in range(len(primes)) if primes[i]]))
Click to reveal output
142913828922