poj2262 Goldbach's Conjecture

依然水题,但是啊。。。两个素数可以相同啊相同!!!!!悲剧。。。。


#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;

bool a[2000000];
int x,y,maxi,n,i,j,k;

int main(){
    memset(a,0,sizeof(bool));
    a[0]=a[1]=true;
    for(i=0;i<2000000;i++)
        if(!a[i]){
            //a[i]=true;
            j=2;
            while(i*j<2000000){
                a[i*j]=true;
                j++;
            }
        }
    a[2]=true;
    //cout<<sum;
    while(scanf("%d",&n),n!=0){
        maxi=-1;
        x=1; y=n-1;
        if(n%2!=0) printf("Goldbach's conjecture is wrong.\n");
        else{
            while(x<=y){
                if(!a[x]&&!a[y]){
                    maxi=0;
                    break;
                }
                x+=2; y-=2;
            }
            if(maxi==-1) printf("Goldbach's conjecture is wrong.\n");
            else printf("%d = %d + %d\n",n,x,y);
            //printf("%d = %d + %d\n",n,x,y);
        }
        //if(maxi==-1) printf("Goldbach's conjecture is wrong.\n");
        //else printf("%d = %d + %d\n",n,x,y);
    }
    return 0;
}


你可能感兴趣的:(poj2262 Goldbach's Conjecture)