Euler problem 50

I was trying to solve the Euler problem number 50, and wrote the following code and got the answer as,
no. of primes = 536
and prime value is 958577
But, when i search the answer for this on internet, it says 543 primes and prime is 997651
why does my program ends even if the sum is not > than 1000000 ???

```    #include
#include
void prime(); // generates prime
int send_prime(long int); // used to send the generated prime
int check_prime(long int); // checks whether obtained sum is prime or not
long int sum = 0;
long int p = 0; // count of primes
int main()
{
prime();
return 0;
}
void prime() {
int count = 0;
for(long int i = 2 ; i <= 1000000 ; i++) {
count = 0;
for(long int j = 2 ; j <= (i/2) ; j++) {
if(i%j == 0) {
count++;
break;
}
}
if(count == 0) {
p++; // number of prime incremented
int check = send_prime(i);
if(check == 0) // to check is sum goes beyond 1 million
break;
}
}
}
int send_prime(long int x) {
sum = sum + x;
if(sum > 1000000)
return 0;
int u = check_prime(sum);
if(u == 1 && sum < 1000000) {
printf("\nnumber of terms = %d\n",p);
printf("\n%d\n",sum);
return 1;
}
else
return 1;
}
int check_prime(long int x) {
int count = 0;
for(long int i = 2 ; i <= x/2 ; i++) {
if(x%i == 0) {
count++;
break;
}
}
if(count == 0)
return 1;
else
return 0;
}```

Replies

You are reading an archived discussion.

How to complete circuit of 1-phase supply under balanced conditions?

In our houses, we have 1-phase supply whose return path is neutral. Now suppose loads get balanced on all the three phases of the 3 phase 4 wire system, then...

Next Gen PS Vita To Be Available In Japan From October 10th For 18,980 Yen

Sony had left this one out of its IFA conference, but it is here now. The new PlayStation Vita was unveiled just now at a press conference in Japan. This...

Celebrate Ganesh chathurthi in a ecofriendly manner

So all of you would have been busy today of preparing and celebrating ganesh chathurthi.SO I want to wish all of you a happy day and I request all of...

India to miss green power target due to slowdown

By G Balachandar Renewable energy sector in the country appears to be facing the brunt of a weak economy, as there has been tardy progress in new capacity addition during...

Train problem: No of trains and cross points

Here is a real world problem. Train takes 33 hours to reach from Secundarabad (SC) to Patna (PNBE). Train from SC leaves @ 10:00 every day Train From PNBE leaves...