Problem Description
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
Analysis
Sieve the prime numbers less than 2,000,000 and sum them. Having a fast algorithm to sieve primes helps a solution run under a few seconds.
Solution
Runs < 2 seconds in Python.
limit = 2000000 sieve = range(limit) for n in xrange(2, int(limit**.5) + 1): if sieve[n]: for i in xrange(n ** 2, limit, n): sieve[i] = 0 print "answer to PE10 = ",sum(sieve)
Comments
This problem changed from a limit of one million in 2008.





Discussion
No comments for “Project Euler Problem 10 Solution”