题意
题目链接
sol
首先考虑当(n = p^x),其中(p)是质数,显然它的因子只有(1, p, p^2, dots p^x)(最多logn个)
那么可以直接dp, 设(f[i][j])表示经过了(i)轮,当前数是(p^j)的概率,转移的时候枚举这一轮的(p^j)转移一下
然后我们可以把每个质因子分开算,最后乘起来就好了
至于这样为什么是对的。(开始瞎扯),考虑最后的每个约数,它一定是一堆质因子的乘积,而每个质因子的概率我们是知道的,所以这样乘起来算是没问题的。
其实本质上还是因为约数和/个数都是积性函数
时间复杂度:(o(sqrt{n} + k log^2 n))
#include<bits/stdc++.h> #define pair pair<int, int> #define mp(x, y) make_pair(x, y) #define fi first #define se second #define int long long #define ll long long #define fin(x) {freopen(#x".in","r",stdin);} #define fout(x) {freopen(#x".out","w",stdout);} using namespace std; const int maxn = 1e6 + 10, mod = 1e9 + 7, inf = 1e9 + 10; const double eps = 1e-9; template <typename a, typename b> inline bool chmin(a &a, b b){if(a > b) {a = b; return 1;} return 0;} template <typename a, typename b> inline bool chmax(a &a, b b){if(a < b) {a = b; return 1;} return 0;} template <typename a, typename b> inline ll add(a x, b y) {if(x + y < 0) return x + y + mod; return x + y >= mod ? x + y - mod : x + y;} template <typename a, typename b> inline void add2(a &x, b y) {if(x + y < 0) x = x + y + mod; else x = (x + y >= mod ? x + y - mod : x + y);} template <typename a, typename b> inline ll mul(a x, b y) {return 1ll * x * y % mod;} template <typename a, typename b> inline void mul2(a &x, b y) {x = (1ll * x * y % mod + mod) % mod;} template <typename a> inline void debug(a a){cout << a << 'n';} template <typename a> inline ll sqr(a x){return 1ll * x * x;} 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 n, k, top, inv[maxn]; pair st[maxn]; int f[10001][1001]; int fp(int a, int p) { int base = 1; while(p) { if(p & 1) base = mul(base, a); a = mul(a, a); p >>= 1; } return base; } int solve(int a, int b) {//a^b memset(f, 0, sizeof(f)); f[0][b] = 1; for(int i = 1; i <= k; i++) for(int j = 0; j <= b; j++) for(int k = j; k <= b; k++) add2(f[i][j], mul(f[i - 1][k], inv[k + 1])); int res = 0; for(int i = 0; i <= b; i++) add2(res, mul(f[k][i], fp(a, i))); return res; } signed main() { for(int i = 1; i <= 666; i++) inv[i] = fp(i, mod - 2); cin >> n >> k; for(int i = 2; i * i <= n; i++) { if(!(n % i)) { st[++top] = mp(i, 0); while(!(n % i)) st[top].se++, n /= i; } } if(n) st[++top] = mp(n, 1); int ans = 1; for(int i = 1; i <= top; i++) ans = mul(ans, solve(st[i].fi, st[i].se)); cout << ans; return 0; } /* 2 (())) ( */
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/605642.html