比赛链接
质数和分解
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 9;
const int mod = 1e9 + 7;
int f[209];
long long num[209];
vector <int> p;
int n;
void init()
{
for(int i = 2; i <= 299; ++i)
{
bool f = 1;
for(int j = 2; j <= sqrt(i); ++j)
{
if(i % j == 0){
f=0;break;
}
}
if(f) p.push_back(i);
}
}
int main()
{
init();
while(cin >> n)
{
memset(f,-0x3f,sizeof(f));
memset(num,0,sizeof(num));
f[0] = 0;
num[0] = 1;
for(int i = 0; p[i] <= n; ++i)
{
for(int j = p[i]; j <= n; ++j)
{
/*if(f[j] < f[j - p[i]] + p[i])
num[j] = num[j-p[i]], f[j] = f[j-p[i]] + p[i];
else if(f[j] == f[j-p[i]] + p[i])
num[j] += num[j-p[i]];*/
//cout << p[i] << " " << j << " "<< num[j] << endl;
num[j] += num[j-p[i]];
}
}
//for(int i = 1; i <= n; ++i)
// cout << num[i] << " ";cout << endl;
long long ans = 0;
for(int i = 0; i <= n; ++i)
{
if(f[i] == n) ans += num[i];
}
//cout << ans << endl;
cout << num[n] << endl;
}
return 0;
}