| ||||||||||
| 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 | |||||||||
打表飘过。。数组开1229,别开小了!!!#include<iostream>
#include<cmath>
using namespace std;
const int Max=1229;
int a[Max];
int isprime(int x)
{
if(x==1) return 0;
if(x==2) return 1;
if(x%2==0) return 0;
int i;
for(i=3;i<=sqrt(x);i+=2)
if(x%i==0) return 0;
return 1;
}
int main()
{
int i,j,sum,count,n;
for(i=2,j=0;i<10000;i++)
if(isprime(i)==1)
a[j++]=i;
// cout<<j<<' '<<a[j-1]<<endl;
while(cin>>n,n!=0){
for(i=count=0;i<Max;i++){
for(j=i,sum=0;j<Max && sum<n;j++)
sum+=a[j];
if(sum==n)
count++;
}
cout<<count<<endl;
}
// system("pause");
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator