# 【BZOJ 1025】[SCOI2009]游戏

【题目链接】:http://www.lydsy.com/JudgeOnline/problem.php?id=1025

【题意】

【题解】

X=a1^b1*a2^b2…ak^bk
->质数唯一分解定理;

{a1^b1,a2^b2…,ak^bk}

f[i][j] = f[i-1][j]+∑(f[i-][j-a[i]^k]) 这里j-a[i]^k>=0

f[tot][0..n]即可;
tot是1..n里面质数的个数.

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x)

typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 1e3 + 100;

int n,tot;
int a[N];
LL f[N][N],ans = 0;

bool is(int x)
{
int len = sqrt(x);
rep1(i, 2, len)
if (x%i == 0)
return false;
return true;
}

void input_data()
{
rei(n);
}

void get_ans()
{
rep1(i, 2, n)
if (is(i))
a[++tot] = i;

f[0][0] = 1;
rep1(i, 1, tot)
{
rep1(j, 0, n)
{
f[i][j] = f[i - 1][j];
int k = a[i];
while (j - k >= 0)
{
f[i][j] += f[i - 1][j - k];
k = k*a[i];
}
}
}

rep1(i, 0, n)
ans += f[tot][i];
}

void output_ans()
{
printf("%lld\n", ans);
}

int main()
{
//freopen("F:\\rush.txt", "r", stdin);
input_data();
get_ans();
output_ans();
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

posted @ 2017-10-04 18:45  AWCXV  阅读(74)  评论(0编辑  收藏  举报