I need to find "Which prime, below one-million, can be written as the sum of the most consecutive primes?". My program gives an answer that is very close to the right answer, but is off by 10. What's wrong with my logic?
#include <iostream>
#include <cmath>
#include <iomanip>
usingnamespace std;
int is_prime(int number)
{
int n=2;
while (n<number) {
if (number%n==0) return 0;
n++;
}
return number;
}
int main()
{
int x=2;
int sum=0;
while (sum+is_prime(x)<1000000) {sum=sum+is_prime(x);x++;}
cout << sum << endl;
}