Problem 010


Project Euler

Summation of primes

Problem 10

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.


A classic prime sieve. Starts by adding 2 to the sum and eliminate all values which are multiple of 2, then add 3 to the sum and eliminate all values which are multiple of 3, and then 5, 7, 11 … so on up to two million. This brute force approach can speed up by limit the values to check be less than \sqrt{n} , where $latext n$ is the limit (e.g. two million).

Advertisements