Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:AC了,代码如下, 这道题目不难

Posted by qdenis at 2009-03-16 09:16:31 on Problem 2262
In Reply To:Re:AC了,代码如下, 这道题目不难 Posted by:qdenis at 2009-03-16 09:16:11
#include <iostream>
#include <math.h>
using namespace std;

bool isprime(int x)
{
	int i;
	double m=sqrt((double)x);
	for(i=2;i<=m;i++)
		if(x%i==0) return false;
	return true;
}

int main()
{
	int n,i;
	while(cin>>n && n)
	{
		bool flag=false;
		for(i=3;i<=n/2;i+=2)
			if(isprime(i) && isprime(n-i))
			{
				flag=true;
				break;
			}
		if(flag) cout<<n<<" = "<<i<<" + "<<n-i<<endl;
		else cout<<"Goldbach's conjecture is wrong."<<endl;

	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator