| ||||||||||
| 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 | |||||||||
筛选法求素数,然后水过。。。#include<stdio.h>
int main()
{
int a[12001],b[1000],i,j,k,n,x,head,tail,sum,ans;
x=0;
memset(a,0,sizeof(a));
for (i=2; i<=12000; i++)
if (!a[i])
{
x++;
b[x]=i;
for (j=i; j<=12000; j+=i) a[j]=1;
}
scanf("%d",&n);
while (n!=0)
{
ans=0;
sum=0;
head=1;
tail=1;
do
{
k=0;
while (sum+b[tail]<=n)
{
sum+=b[tail];
tail++;
k=1;
}
if (sum==n && k) ans++;
sum+=b[tail];
tail++;
k=0;
while (sum>n)
{
sum-=b[head];
head++;
k=1;
}
if (sum==n && k) ans++;
}while (head<tail);
printf("%d\n",ans);
scanf("%d",&n);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator