We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
For those that aren't passing test case 6 & 7 it's because your prime checking algorithm isn't efficient enough.
There is a very efficient algorithm called the Sieve of Eratosthenes that is very simple. This alorithm will help you create an array of booleans of size 1000000 that will tell you whether a number is a prime or not. Wikipedia Article
Create another array that holds the sum of all of the prime numbers less than the index (use the array that we created above)
Once you have the array of sums, simply read the input number, and print sum[inputNumber]. I did this solution in C++ and all test cases finish in < .02 seconds
Project Euler #10: Summation of primes
You are viewing a single comment's thread. Return to all comments →
For those that aren't passing test case 6 & 7 it's because your prime checking algorithm isn't efficient enough.
There is a very efficient algorithm called the Sieve of Eratosthenes that is very simple. This alorithm will help you create an array of booleans of size 1000000 that will tell you whether a number is a prime or not. Wikipedia Article
Create another array that holds the sum of all of the prime numbers less than the index (use the array that we created above)
Once you have the array of sums, simply read the input number, and print sum[inputNumber]. I did this solution in C++ and all test cases finish in < .02 seconds
Reply if you need any help.