哥德巴赫猜想

来源:互联网 发布:mysql insert慢 io 编辑:程序博客网 时间:2024/05/17 22:32

题目描述

输入N(N<=10000),验证4~N所有偶数是否符合哥德巴赫猜想。

(N为偶数)。

如果一个数,例如10,则输出第一个加数相比其他解法最小的方案。如10=3+7=5+5,则10=5+5是错误答案。

输入输出格式

输入格式:

第一行N

输出格式:

4=2+2 6=3+3 …… N=x+y

#include<iostream>#include<cstdio>#include<cmath>using namespace std;int n,m,s,t,a[10005],cnt,bnt;int main(){cin>>s;a[1]=2;cnt=1;for(register int x=3;x<=s;x++){for(register int y=2;y<=sqrt(x);y++){if(x%y==0){bnt++;break;}}if(bnt==0){cnt++;a[cnt]=x;}else{bnt=0;}}//for(int z=1;z<=cnt;z++)//{//cout<<a[z]<<endl;//}for(int l=2;l<=s;l=l+2){for(m=1;m<=cnt;m++){for(n=m;n<=cnt;n++){if(a[m]+a[n]==l){cout<<l<<"="<<a[m]<<"+"<<a[n]<<endl;t++;break;}}if(t==1){t=0;break;}}}}