Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 9435 | Accepted: 5407 |
Description
numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20.
Your mission is to write a program that reports the number of representations for the given positive integer.
Input
Output
Sample Input
2 3 17 41 20 666 12 53 0
Sample Output
1 1 2 3 0 0 1 2
Source
#include<cstdio>
bool isprime[10010]={false};
int num=0,prime[5000];
int a[10010]={0};
void init()
{
isprime[1]=isprime[0]=true;
for(int i=2;i*i<=10010;i++)
if(!isprime[i])
{
for(int j=i*i;j<=10010;j+=i)
isprime[j]=true;
}
for(int i=2;i<=10010;i++)
if(!isprime[i]) prime[++num]=i;
}
int main()
{
init();
for(int i=1;i<=10010;i++)
{
for(int j=1;j<=num;j++)
{
if(prime[j]==i)
{
a[i]++;
break;
}
if(prime[j]>i) break;
int sum=0;
int t=j;
while(sum<i)
{
sum+=prime[t];
t++;
}
if(sum==i) a[i]++;
}
}
int n;
while(scanf("%d",&n)!=EOF)
{
if(n==0) break;
printf("%d/n",a[n]);
}
return 0;
}