您的位置:首页 > 其它

poj 2262 素数

2013-01-23 10:38 211 查看
题目链接:http://poj.org/problem?id=2262

发现刷题的时候就需要简单难题结合,当难题把自己打击的泄气的时候确实需要这简单的水题哈!

#include<iostream>
using namespace std;
int main()
{
bool a[1000005];
int i,j,n;
for(i=1; i<=1000000; i++)
a[i]=true;
for(i=2; i<=500000; i++)
{
j=i+i;
while(j<=1000000)
{
a[j]=false;
j+=i;
}
}
while(1)
{
cin>>n;
if(n==0)
break;
for(i=2; i<=n/2; i++)
if(a[i]==true && a[n-i]==true)
break;
if(i!=n/2+1)
cout<<n<<" = "<<i<<" + "<<n-i<<endl;
else
cout<<"Goldbach's conjecture is wrong."<<endl;
}
return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: