| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
刚ac得代码,算是费了一点周折,主要是在优化上要下功夫,不然很容易re得。#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator