标签:
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 39435 | Accepted: 15119 |
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
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
int prime[1000010]={2,3,5};
int k=3;
int ip[1000010]={0};
void is_prime()
{
int i,j;
int flag=0;
int gad=2;
ip[2]=1;ip[3]=1;ip[5]=1;
for(i=7;i<=1000010;i+=gad){
flag=0;
gad=6-gad;
for(j=0;prime[j]*prime[j]<=i;j++){
if(i%prime[j]==0){
flag=1;
break;
}
}
if(!flag){
prime[k++]=i;
ip[i]=1;
}
}
}
int main()
{
int n,i,j;
is_prime();
while(~scanf("%d",&n)){
if(!n) break;
int f=0;
for(i=0;i<=k;i++){
j=n-prime[i];
if(ip[j]){
f=1;
break;
}
}
if(!f)
printf("Goldbach's conjecture is wrong.\n");
else
printf("%d = %d + %d\n",n,prime[i],j);
}
return 0;
}
POJ 2262-Goldbach's Conjecture(素数筛)
标签:
原文地址:http://blog.csdn.net/u013486414/article/details/44260305