素数筛 uva 543

时间:2022-06-18 05:07:08

给你一个n求出n由2个奇质因子的和  这2个因子差最大

没有就输出‘Goldbach's conjecture is wrong.

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<math.h> using namespace std;
#define MAXN 1000010
bool pri[MAXN]; int main()
{
memset(pri,,sizeof(pri)); for(int i=;i<=;i++)
{
if(!pri[i])
for(int j=i*i;j<=MAXN;j=j+i)
pri[j]=;
}
int n; while(scanf("%d",&n)!=EOF&&n)
{
int a=n/,i;
for(i=;i<=a;i++)
if(!pri[i]&&!pri[n-i])
{
printf("%d = %d + %d\n",n,i,n-i);
break;
}
if(i>a)
printf("‘Goldbach's conjecture is wrong.\n");
} return ;
}