CF1097D 【Makoto and a Blackboard】

We consider for a \ (N \) , if he became his number about \ (the X-\) , it will become a problem child

We define \ (F (n, k) \) to a desired number k of times n

Then we have \ (F. (N, K) = \ sum_ {X | n} F. (X, K -. 1) * \ {d}. 1 FRAC {} \) (where n d is the number of the divisor)

Since \ (N \) the number of divisor certainly \ (\ sqrt N \) within now we have a \ (O (\ sqrt NK) \) violence of the

In front of \ (\ sqrt N \) certainly can not be omitted, can we on the \ (K \) start?

We consider \ (N \) is a prime number, then the answer is \ (\ frac {N + 2 ^ k - 1} {2 ^ k} \)

Consider wave \ (N = p ^ x \ ) where p is a prime number, then we consider the above-mentioned \ (for Solving the DP \)

DP provided $ [i] [J] (after this operation is the i, as \) \ P ^ $ J probability

\(dp[i][j] = \sum_{l = 1}^x dp[i - 1][l] * \frac{1}{j}\)

Finally, the answer to the \ (\ sum_ {j = 1 } ^ {x} dp [k] [j] * p ^ j \)

We found that each \ (p_i ^ {j} \ ) independently of each other, which in turn is a multiplicative function

\(sum[i][j] * sum[i][k] = sum[i][j * k](gcd(j, k) == 1)\)

Proof if we do return to define, say an \ (p_1 ^ j * p_2 ^ 0 \) probability of the X-, \ (p_1 ^ 0 * P_2 k ^ \) probability of y, then \ (p_1 ^ j * p_2 ^ k \) is a certain probability for the \ (x * y \)

So we just need to \ (N \) decomposition of the quality factor then sets a \ (\ Prod \) to

Such complexity is \ (\ sqrt N + K * log ^ 3N = 10 ^ 9 \)

However, due to \ (log \) is not necessarily to 2, so the complexity of solving the problem is over

\(Code:\)

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define int long long
#define D double
#define inf 123456789
#define mod 1000000007
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define rep(i, s, t) for(re int i = s; i <= t; ++ i)
#define drep(i, s, t) for(re int i = t; i >= s; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 1000005
int n, m, prim[maxn], tot, dis[maxn], dp[maxn][20], ans, inv[100], Ans = 1;
il void get(int x) {
    for(re int i = 2; i * i <= x; ++ i) {
        if(x % i == 0) prim[++ tot] = i;
        while(x % i == 0) x /= i, ++ dis[tot];
    }
    if(x != 1) prim[++ tot] = x, ++ dis[tot];
}
il int qpow(int a, int b) {
    int r = 1;
    while(b) {
        if(b & 1) r = r * a % mod;
        b >>= 1, a = a * a % mod;
    }
    return r;
}
signed main() {
    n = read(), m = read();
    get(n);
    rep(i, 1, 60) inv[i] = qpow(i, mod - 2);
    rep(T, 1, tot) {
        mem(dp, 0), dp[0][dis[T]] = 1, ans = 0;
        rep(i, 1, m) {
            rep(j, 0, dis[T]) {
                rep(k, j, dis[T]) dp[i][j] = (dp[i - 1][k] * inv[k + 1] + dp[i][j]) % mod;
            }
        }
        rep(i, 0, dis[T]) ans = (ans + dp[m][i] * qpow(prim[T] % mod, i) % mod);
        Ans = ans * Ans % mod;
    }
    printf("%lld", Ans);
    return 0;
}

Guess you like

Origin www.cnblogs.com/bcoier/p/11621145.html