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

刚ac得代码,算是费了一点周折,主要是在优化上要下功夫,不然很容易re得。

Posted by 20083331 at 2009-04-26 19:10:16 on Problem 2909
#include<iostream>
#include<cmath>
using namespace std;

int prime[10000];
short judge(long x)
{
long i;
for(i=2;i<=sqrt((double)(x));i++)
{
	if(x%i==0)
	{
		return 1;
	}
}
return 0;
}


int main()
{
long i,j,m=0;
for(i=2;i<=32769;i++)
{
	if(judge(i)==0)
	{
		prime[m]=i;
		m++;
	}
}
long n;
while(cin>>n,n!=0)
{
	int count=0;
	int len;
	for(i=0;n>=prime[i];i++);
	len=i;
	for(i=0;prime[i]<=n/2;i++)
	{
		for(j=len+2;prime[j]>=n/2;j--)
		{
			if(prime[i]+prime[j]==n)
			{
				count++;
				break;
			}
		}
	}
	cout<<count<<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