Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 41582 | Accepted: 15923 |
Description
Every even number greater than 4 can be
written as the sum of two odd prime numbers.
8 = 3 + 5. Both 3 and 5 are odd prime numbers.
20 = 3 + 17 = 7 + 13.
42 = 5 + 37 = 11 + 31 = 13 + 29 = 19 + 23.
Input
Output
Sample Input
8 20 42 0
Sample Output
8 = 3 + 5 20 = 3 + 17 42 = 5 + 37
Source
#include <iostream> #include<cstdio> #include<cstring> using namespace std; #define N 1000000 int n,a[N]; bool pr[N]; void pdd() { int i,j; for(i=0;i<1000000;i++) a[i]=1; a[0]=0; a[1]=0; for(i=2;i<1000000;i++) { if(a[i]==1) { for(j=i*2;j<1000000;j+=i) a[j]=0; } } } int main() { int num; int i,flag; pdd(); while(scanf("%d",&num)!=EOF&&num!=0) { for(flag=0,i=2;i<num;i++) { if(a[i]==1&&a[num-i]==1) { printf("%d = %d + %d\n",num,i,num-i); flag=1; break; } } if(flag==0) printf("Goldbach‘s conjecture is wrong.\n"); } return 0; }
原文:http://www.cnblogs.com/yoyo-sincerely/p/5024676.html