# 【数位DP】【P4317】花神的数论题

## Limitations

$1 \leq n \leq 10^{15}$

## Solution

$f_{i,j} = f_{i-1,j+1} f_{i-1,j}$

## Code

#include <cstdio>
#include <cstring>

const int maxn = 64;
const int MOD = 10000007;

ll n;
int cnt, upc = -1;
ll ans = 1;
ll frog[maxn][maxn];
int MU[maxn];

ll calc(const int x);
ll mpow(const int x, ll y);

int main() {
freopen("1.in", "r", stdin);
qr(n);
do cnt += (MU[++upc] = n & 1); while (n >>= 1);
for (int i = 1; i < 60; ++i) {
ans = ans * mpow(i, calc(i)) % MOD;
}
ans = ans * cnt % MOD;
qw(ans, '\n', true);
return 0;
}

ll calc(const int x) {
int cnt = x - 1;
memset(frog, 0, sizeof frog);
frog[upc][x] = 1;
for (int i = upc - 1; ~i; --i) {
int di = i + 1;
for (int j = 0; j <= x; ++j) {
frog[i][j] = frog[di][j + 1] + frog[di][j];
}
if (MU[i] && ~cnt) {
++frog[i][cnt--];
}
}
return frog[0][0];
}

ll mpow(const int x, ll y) {
ll _ret = 1, _tmp = x;
while (y) {
if (y & 1) {
_ret = _ret * _tmp % MOD;
}
_tmp = _tmp * _tmp % MOD;
y >>= 1;
}
return _ret;
}


## Summary

posted @ 2019-08-31 02:02  一扶苏一  阅读(166)  评论(0编辑  收藏  举报