2201: Prime and Decompounding
Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
---|---|---|---|---|---|
![]() | 3s | 8192K | 308 | 165 | Standard |
A positive interger except 1 can be decompounded to the sum of several prime numbers(include only one number). For exsample, four of the different forms in essence of the decompounding for 9 are: 9 = 2 + 5 + 2 = 2 + 3 + 2 + 2 = 3 + 3 + 3 = 2 + 7. Here the different forms in essence means that one expression can't be the same with others by exchange numbers in the it. Now do you know how many different decompounding forms in essence for any given number N.
Input and Output
The input will consist several lines, each line is a positive interger N(2 < N <= 330) for which output the anwser in a single line.Sample Input
2 200
Sample Output
1 9845164
This problem is used for contest: 29
#include<stdio.h>
int prime[350]={0};
int a[400]={0};
int p[300];
void pri()
{
int i,j;
for(i=2;i*i<350;i++)
{
if(prime[i]==0)
{
for(j=i*i;j<350;j+=i)
{
prime[j]=1;
}
}
}
}
int main()
{
pri();
int n,i,j,l=0;
for(i=2;i<350;i++)
{
if(prime[i]==0) p[l++]=i;
}
a[0]=1;
for(i=0;i<l;i++)
{
for(j=p[i];j<350;j++)
{
a[j]+=a[j-p[i]];
}
}
while(scanf("%d",&n)==1)
{
printf("%d/n",a[n]);
}
return 0;
}