| ||||||||||
| 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 | |||||||||
刚开始题目没有看清楚以为不连续的素数也可以,然后还开数组时少写了个0,现在终于AC了,贴上代码#include<stdio.h>
#include<math.h>
int a[10010];
int main(){
int i,count,j,n=0,b,temp,flag=0;
a[n++]=2;
for(i=3;i<=10010;i++){
for(j=2;j<=floor(i/2);j++)
if(i%j==0) break;
if(j>floor(i/2)) a[n++]=i;
}
while(1){
flag=0;
count=0;
scanf("%d",&b);
if(b==0) break;
for(i=0;a[i]<=b&&i<n;i++)
{
temp=0;
for(j=i;a[j]<=b&&j<n;j++)
{
temp+=a[j];
if(temp==b)
{
count++;
flag=1;
break;
}
if(temp>b) break;
}
}
if(flag==0) printf("0\n");
else printf("%d\n",count);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator