2201: Prime and Decompounding
Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
---|---|---|---|---|---|
![]() | 3s | 8192K | 400 | 209 | Standard |
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
Submit / Problem List / Status / Discuss
#include <iostream>
#include <stdio.h>
using namespace std;
int prime[350]={0};
long long c1[350]={0};
long long c2[350]={0};
int main()
{
int n=340;
for(int i=2;i<=n;i++)
{
for(int j=2;j*i<=n;j++)
{
prime[j*i]=1;
}
}
for(int i=0;i<=n/2;i++)
{
c1[i*2]=1;
}
for(int i=3;i<n;i++)
{
if(prime[i]==0)
{
for(int j=0;j<n;j++)
{
for(int k=0;k+j<n;k+=i)
{
c2[k+j]+=c1[j];
}
}
for(int i=0;i<=n;i++)
{
c1[i]=c2[i];
c2[i]=0;
}
}
}
while(scanf("%d",&n)==1)
{
cout<<c1[n]<<endl;
}
return 0;
}