该学习了。。。
还是那里不对!细心的看一下!
#include <stdio.h>
#include <stdlib.h>
int sum(long a)
{
long i = 2;
while(i*i<a)
{
if(a%i==0)
{
return(0);
}
i++;
}
return(1);
}
int main()
{
long a, num;
while(EOF != (scanf("%ld", &num)) && num%2==0&&num!=0)
{
a = 3;
while(a < num)
{
if(sum(a)&&sum(num - a))
{
printf("%ld = %ld + %ld\n", num, a,num - a);
break;
}
a += 2;
}
if(!(sum(a)&&sum(num - a)))
printf("Goldbach's conjecture is wrong.\n");
}
return 0;
}
如果我这样写的话就出现了超时!HIT-Online Judge,process result is Time limit exceed.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int sum(long a)
{
long i = 2;
while(i < a/2)
{
if(a%i==0)
{
return(0);
}
i++;
}
return(1);
}
int main()
{
long a, num;
while(EOF != (scanf("%ld", &num)) && num%2==0 && num!=0)
{
a = 3;
while(a < num/2)
{
if(sum(a)&&sum(num - a))
{
printf("%ld = %ld + %ld\n", num, a,num - a);
break;
}
a += 2;
}
}
return 0;
}