这题超时了N遍,就是不记得筛选法求素数了,哎~~~这次可要牢记了,其他的就不多说了。。。
- #include<iostream>
- #include<time.h>
- short prime[1000000];
- using namespace std;
- int main()
- {
- int i,j,s=0,n,num;
- memset(prime,0,sizeof(prime));
- for(i=2;i<1000000;i++)
- for(j=2;i*j<1000000;j++)
- {
- if(prime[i*j]==0)
- prime[i*j]=1;
- }
- while(scanf("%d",&n)&&n!=0)
- {
- for(i=3;i*2<=n;i+=2)
- if(prime[i]==0&&prime[n-i]==0)
- {
- printf("%d = %d + %d\n",n,i,n-i);
- goto end;
- }
- printf("Goldbach's conjecture is wrong.\n");
- end:;
- }
- return 0;
- }