poj 2262 素数

题目链接: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;

}

你可能感兴趣的:(poj 2262 素数)