题意:给出n和k,n每次会等概率的变成n的一个因子,问这样k次以后的期望大小
每个质因子贡献独立,变成一个因子就相当于变了质因子的次数
所以分解质因数以后对每个质因子做dp
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;
#define mp make_pair
#define pb push_back
int dp[205], inv[205], ans, pre[205], n, k;
vector< pair<int, int> >v;
inline void divide(int n) {
int cur = n;
for (int i = 2; i * i <= n; ++i)
if (cur % i == 0) {
int tot = 0;
do cur /= i, ++tot; while (cur % i == 0);
v.pb(mp(i, tot));
}
if (cur > 1) v.pb(mp(cur, 1));
}
// n = prod {p_i^{k_i}}
//dp[j] p_i^j 对答案贡献次数的期望
signed main() {
cin >> n >> k;
divide(n);
ans = 1;
inv[1] = 1;
for (int i = 2; i <= 200; ++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
for (auto it = v.begin(); it != v.end(); ++it) {
fill(dp, dp + 200, 0);
dp[it->second] = 1;
for (int j = 1; j <= k; ++j) {
fill(pre, pre + 200, 0);
for (int l = 0; l <= it->second; ++l) (pre[0] += dp[l] * inv[l + 1] % mod) %= mod, (pre[l + 1] -= dp[l] * inv[l + 1] % mod) %= mod; //p_i^k对dp[0]..dp[k]都有dp[l] / (l+1)的贡献,差分
for (int l = 1; l <= it->second; ++l) (pre[l] += pre[l - 1]) %= mod;
for (int l = 0; l <= it->second; ++l) dp[l] = pre[l];
}
int res = 0, res1 = 1;
for (int j = 0; j <= it->second; ++j) (res += res1 * dp[j] % mod) %= mod, (res1 *= it->first) %= mod; //统计答案
(ans *= res) %= mod;
}
cout << (ans + mod) % mod;
return 0;
}