http://codeforces.com/contest/757/problem/E 題意 Sol 非常騷的一道題 首先把給的式子化一下,設$u = d$,那麼$v = n / d$ $$f_r(n) = \sum_{d \mid n} \frac{f_{r - 1}(d) + f_{r - 1} ...
http://codeforces.com/contest/757/problem/E
題意
Sol
非常騷的一道題
首先把給的式子化一下,設$u = d$,那麼$v = n / d$
$$f_r(n) = \sum_{d \mid n} \frac{f_{r - 1}(d) + f_{r - 1}(\frac{n}{d})}{2}$$
$$= \sum_{d\mid n} f_{r - 1}(d)$$
很顯然,這是$f_r(n)$與$1$的狄利克雷捲積
根據歸納法可以證明$f_r(n)$為積性函數
我們可以對每個質因數分別考慮他們的貢獻
考慮$f_0(p^k) = [k =0]+1$,與$p$是無關的,因此我們只要枚舉$r$和$k$就好
$f_r(p^k) = \sum_{i = 0}^k f_{r - 1}(p^i)$
首碼和優化dp
#include<cstdio> #include<cmath> #define LL long long using namespace std; const int MAXN = 1e6 + 10, INF = 1e9 + 10, mod = 1e9 + 7; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } int prime[MAXN], tot, vis[MAXN]; LL f[MAXN][22]; void GetPrime(int N) { for(int i = 2; i <= N; i++) { if(!vis[i]) prime[++tot] = i; for(int j = 1; j <= N && i * prime[j] <= N; j++) { vis[i * prime[j]] = 1; if(i % prime[j] == 0) break; } } } void Pre(int N, int M) { f[0][0] = 1;//f[i][k] f_r(p^k) for(int i = 1; i <= M; i++) f[0][i] = 2; for(int r = 1; r <= N; r++) { LL sum = 0; for(int k = 0; k <= M; k++) { sum += f[r - 1][k]; (f[r][k] += sum ) %= mod; } } } main() { GetPrime(1e6 + 5); Pre(1e6 + 5, 21); int Q = read(); while(Q--) { int r = read(), n = read(); LL ans = 1; for(int i = 1; i <= tot && prime[i] <= sqrt(n); i++) { if(n % prime[i]) continue; int num = 0; while(!(n % prime[i])) num++, n /= prime[i]; ans = 1ll * ans * (f[r][num]) % mod; } if(n > 1) ans = (1ll * ans * f[r][1]) % mod; printf("%I64d\n", ans); } } /* */