Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 15369 | Accepted: 8525 |
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 <stdio.h>
int prime[10000],tot=0;
int check(int x)
{
int i,j;
for(i=0;i<tot;i++)
if (x % prime[i]==0) return 0;
return 1;
}
int main()
{
int i,j;
int num,ans,sum;
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
for(i=2;i<10010;i++)
if (check(i)==1) prime[tot++]=i;
// for(i=0;i<tot;i++) printf("%d ",prime[i]);
scanf("%d",&num);
while(num)
{
ans=0;
for(i=0;prime[i]<=num;i++)
{
sum=0;
for(j=i;j<tot&&sum<num;j++)
sum+=prime[j];
if (sum==num) ++ans;
}
printf("%d\n",ans);
scanf("%d",&num);
}
}