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
完全背包的模型,注意细节就行了。。。。。
#include <iostream>
#include <cmath>
using namespace std;
#define MAXN 1000000
int hash[1000]; //打表保存2-330之间的素数,方便后面计算、、、、
int f[MAXN];
bool is_prime(int n)
{
int i;
for(i = 2; i <= sqrt(n); i++)
{
if(n%i==0)
return false;
}
return true;
}
int main()
{
int i, count = 0, j;
for(i = 2; i <= 330; i++)
{
if(is_prime(i))
{
hash[count] = i;
count++;
}
}
/* for(i = 0; i < count; i++)
{
cout<<hash[i]<<" ";
}
cout<<endl;*/
f[0] = 1; //完全背包的模型、、、、、、
for(i = 0; i < count; i++)
{
for(j = hash[i]; j < 100000; j++)
{
f[j] += f[j-hash[i]];
}
}
int n;
while(cin>>n)
{
cout<<f[n]<<endl;
}
return 0;
}