D. Makoto and a Blackboard(积性函数,期望dp)

D. Makoto and a Blackboard

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Makoto has a big blackboard with a positive integer nn written on it. He will perform the following action exactly kk times:

Suppose the number currently written on the blackboard is vv. He will randomly pick one of the divisors of vv (possibly 11 and vv) and replace vv with this divisor. As Makoto uses his famous random number generator (RNG) and as he always uses 5858 as his generator seed, each divisor is guaranteed to be chosen with equal probability.

He now wonders what is the expected value of the number written on the blackboard after kk steps.

It can be shown that this value can be represented as PQPQ where PP and QQ are coprime integers and Q≢0(mod109+7)Q≢0(mod109+7). Print the value of P⋅Q−1P⋅Q−1 modulo 109+7109+7.

Input

The only line of the input contains two integers nn and kk (1≤n≤10151≤n≤1015, 1≤k≤1041≤k≤104).

Output

Print a single integer — the expected value of the number on the blackboard after kk steps as P⋅Q−1(mod109+7)P⋅Q−1(mod109+7) for PP, QQ defined above.

Examples

input

Copy

6 1

output

Copy

3

input

Copy

6 2

output

Copy

875000008

input

Copy

60 5

output

Copy

237178099

Note

In the first example, after one step, the number written on the blackboard is 11, 22, 33 or 66 — each occurring with equal probability. Hence, the answer is 1+2+3+64=31+2+3+64=3.

In the second example, the answer is equal to 1⋅916+2⋅316+3⋅316+6⋅116=1581⋅916+2⋅316+3⋅316+6⋅116=158.

题意:一开始你手中有一个数n,每一轮你都会等概率的把这个数变成它的因子,k轮后求这个数大小的期望。

题解:首先这个期望是一个积性函数(???为啥,大佬说是就是吧),那么对于一个积性函数,他的期望可以变为他各个质因子期望的乘积,设dp[i][j]代表第i轮这个质因子的幂为j的期望次数,设上一轮的幂为k,那么这一轮的j都会由上一轮转换的概率为1/(k+1),处理期望dp即可

#include<bits/stdc++.h>
using namespace std;
#define Sheryang main
const int maxn=1e5+7;
typedef long long ll;
const int mod=1e9+7;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();if(c == '-')Nig = -1,c = getchar();while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();return Nig*x;}
#define read read()

/* keep hungry and keep calm! */
ll dp[(int)1e4+7][62],n,k,inv[62];

ll qpow(ll a,ll b){
    ll ans=1;a%=mod;
    while(b){
        if(b&1) ans=(ans*a)%mod;
        a=(a*a)%mod;b/=2;
    }
    return ans;
}

ll solve(ll p,int e){
    dp[0][e]=1;
    for(int i=0;i<e;i++) dp[0][i]=0;

    for(ll i=1;i<=k;i++){
        for(int j=0;j<=e;j++){
            dp[i][j]=0;
            for(int k=j;k<=e;k++){
                dp[i][j]=(dp[i][j]+dp[i-1][k]*inv[k+1]%mod)%mod;
            }
        }
    }
    ll tmp=0,t=1;
    for(int i=0;i<=e;i++){
        tmp=(tmp+t*dp[k][i]%mod)%mod;
        t=(t*p)%mod;
    }
    return tmp;
}

int Sheryang()
{
    inv[1]=1;
    for(int i=2;i<=60;i++){
        inv[i]=qpow(i,mod-2);
    }

    n=read,k=read;
    ll ans=1;

    for(ll i=2;i*i<=n;i++){
        int cot=0;
        while(n%i==0) cot++,n/=i;
        if(cot) ans=(ans*solve(i,cot)%mod)%mod;
    }
    if(n>1) ans=(ans*solve(n,1)%mod)%mod;

    printf("%lld\n",ans);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sudu6666/article/details/86528365