Project Euler: Problem 10

Dec 14, 2025

🚨

Spoiler alert: This post contains spoilers for Project Euler.

Problem 10

projecteuler p10 (light) Sum of Primes Less Than 2 Million

Approach

This looks like another opportunity to use the Sieve of Eratosthenes. I can basically recycle my answer from Problem 7.

Using the sieve, we can filter out all the non-primes less than 2,000,000. We'll maintain an array where 0 represents a composite and 1 represents a prime number. Then we can sum the indices of the array where i == 1.

JS Solution

Conclusion

The Sieve of Eratosthenes proves useful again. I've read that prime sieves come up often in these problems. Will be interesting to get to a point where a more advanced sieve is necessary.

Final answer

142,913,828,922142,913,828,922

Ryan McIntire