Makoto has a big blackboard with a positive integer n written on it. He will perform the following action exactly k

times:

Suppose the number currently written on the blackboard is v

. He will randomly pick one of the divisors of v (possibly 1 and v) and replace v with this divisor. As Makoto uses his famous random number generator (RNG) and as he always uses 58

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 k

steps.

It can be shown that this value can be represented as PQ

where P and Q are coprime integers and Q≢0(mod109+7). Print the value of P⋅Q−1 modulo 109+7

.

Input

The only line of the input contains two integers n

and k (1≤n≤1015, 1≤k≤104

).

Output

Print a single integer — the expected value of the number on the blackboard after k

steps as P⋅Q−1(mod109+7) for P, Q

defined above.

Examples

Input
6 1
Output
3
Input
6 2
Output
875000008
Input
60 5
Output
237178099

题意:开始给定一个数N,然后让你K轮如下操作:等概率的变为当前数的一个因子,求期望。

思路:发现有点像孟德尔定律的数据,其实就是在暗示我们:豌豆的几种颜色可以单独算,然后作乘。

事实上就是这样的,对于每个素数因子,我们假设他在N中的幂为p(a^p,本题当a=2时,p最大为50),那么我们可以算出最后幂为1到p的概率。 而不同素因子之间不会相互影响。

所以我们预处理出开始幂为p,K轮后幂为q的次数mp[p][q];然后就可以对于每个素数得到其概率,然后累乘即可。

(注意不要爆ll

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
using namespace std;
const int maxn=;
const int Mod=1e9+;
ll ans,a[maxn],f[maxn],rev[maxn],tot,mp[][],M[][],sum; int K;
int qpow(ll a,int x){
int res=; while(x){
if(x&) res=1LL*res*a%Mod;
a=1LL*a*a%Mod; x>>=;
} return res;
}
ll get(int p)
{
f[p]++; ll tmp=qpow(qpow(f[p],K),Mod-),res=;
rep(i,,f[p]) {
res=(res+1LL*mp[f[p]][i]*tmp%Mod)%Mod;
tmp=tmp*a[p]%Mod;
}
return res;
}
void solve(int p)
{
ll tmp=; mp[p][p]=;
rep(i,,K){
rep(j,,p) M[p][j]=1LL*mp[p][j]*p%Mod,mp[p][j]=;
rep(j,,p) {
rep(k,,j) mp[p][k]=(mp[p][k]+1LL*M[p][j]*rev[j]%Mod)%Mod;
}
}
}
int main()
{
ll N,tN; scanf("%lld%d",&N,&K); tN=N;
rev[]=; rep(i,,) rev[i]=qpow(i,Mod-);
rep(i,,) solve(i); ans=1LL;
for(ll i=;i*i<=tN;i++){
if(tN%i==){
a[++tot]=i; while(tN%i==) tN/=i,f[tot]++;
sum=sum*(f[tot]+);
}
}
if(tN>) a[++tot]=tN,f[tot]=;
rep(i,,tot) ans=1LL*ans*get(i)%Mod;
printf("%lld\n",ans);
return ;
}

CodeForces - 1097D:Makoto and a Blackboard (积性)的更多相关文章

  1. CF1097D Makoto and a Blackboard 积性函数、概率期望、DP

    传送门 比赛秒写完ABC结果不会D--最后C还fst了qwq 首先可以想到一个约数个数\(^2\)乘上\(K\)的暴力DP,但是显然会被卡 在\(10^{15}\)范围内因数最多的数是\(978217 ...

  2. Codeforces 1097D. Makoto and a Blackboard

    传送门 首先考虑如果 $n$ 只有一个质因数的情况,即 $n=p^t$ 那么显然可以 $dp$ ,设 $f[i][j]$ 表示第 $i$ 步,当前剩下 $p^j$ 的概率 那么转移很简单: $f[i] ...

  3. Codeforces E. Bash Plays with Functions(积性函数DP)

    链接 codeforces 题解 结论:\(f_0(n)=2^{n的质因子个数}\)= 根据性质可知\(f_0()\)是一个积性函数 对于\(f_{r+1}()\)化一下式子 对于 \[f_{r+1} ...

  4. CF 1097D Makoto and a Blackboard

    算是记一下昨天晚上都想了些什么 官方题解   点我 简单题意 给定两个正整数$n$和$k$,定义一步操作为把当前的数字$n$等概率地变成$n$的任何一个约数,求$k$步操作后的期望数字,模$1e9 + ...

  5. Makoto and a Blackboard CodeForces - 1097D (积性函数dp)

    大意: 初始一个数字$n$, 每次操作随机变为$n$的一个因子, 求$k$次操作后的期望值. 设$n$经过$k$次操作后期望为$f_k(n)$. 就有$f_0(n)=n$, $f_k(n)=\frac ...

  6. D. Makoto and a Blackboard(积性函数+DP)

    题目链接:http://codeforces.com/contest/1097/problem/D 题目大意:给你n和k,每一次可以选取n的因子代替n,然后问你k次操作之后,每个因子的期望. 具体思路 ...

  7. Bash Plays with Functions CodeForces - 757E (积性函数dp)

    大意: 定义函数$f_r(n)$, $f_0(n)$为pq=n且gcd(p,q)=1的有序对(p,q)个数. $r \ge 1$时, $f_r(n)=\sum\limits_{uv=n}\frac{f ...

  8. CF 1097D - Hello 2019 D题: Makoto and a Blackboard

    目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:传送门  Portal  原题目描述在最下面.  给一个数n ...

  9. CF1097D Makoto and a Blackboard

    题目地址:CF1097D Makoto and a Blackboard 首先考虑 \(n=p^c\) ( \(p\) 为质数)的情况,显然DP: 令 \(f_{i,j}\) 为第 \(i\) 次替换 ...

  10. codeforces757E. Bash Plays with Functions(狄利克雷卷积 积性函数)

    http://codeforces.com/contest/757/problem/E 题意 Sol 非常骚的一道题 首先把给的式子化一下,设$u = d$,那么$v = n / d$ $$f_r(n ...

随机推荐

  1. Qt5_QString_测试

    ZC: 下面的测试效果看,可以只是用 “QString.isEmpty()” 或者 “QString == ""”来判断 QString是否为 空或者NULL . 1. 1.1. ...

  2. [ios]MKMapView中使用MKPolyline画线

    参考:http://blog.sina.com.cn/s/blog_9e8867eb0101dt76.html 首先在MapView.h中 #import <MapKit/MapKit.h> ...

  3. android中 检查网络连接状态的变化,无网络时跳转到设置界面

    1:在AndroidManifest.xml中加一个声明 <receiver android:name="NetCheckReceiver">    <inten ...

  4. Insert Delete GetRandom O(1)

    2018-07-15 18:36:29 问题描述: 问题求解: private ArrayList<Integer> ls; private HashMap<Integer, Int ...

  5. [.NET开发] C# 读写文件

    1.C#读文件 按行读取文件: public void Read(string path) { StreamReader sr = new StreamReader(path,Encoding.Def ...

  6. Confluence 6 结构(Schema )设置

    基本 DN(Base DN) 根专有名称(DN)将会在你在目录服务器上运行查询的时候使用到.例如: o=example,c=com cn=users,dc=ad,dc=example,dc=com 针 ...

  7. uva-10561-nim

    题意: 给出一个连续的棋盘,有的位置为'.',有的位置为'X',二者轮流下子,当有一方获得连续三个子的时候取胜. 对于胜态,一种情况是当前局面出现"XX"/"X.X&qu ...

  8. JavaScript学习总结(七)——JavaScript函数(function)

    一.函数基本概念 为完成某一功能的程序指令(语句)的集合,称为函数. 二.JavaScript函数的分类 1.自定义函数(我们自己编写的函数),如:function funName(){} 2.系统函 ...

  9. 063——VUE中vue-router之重定向redirct的使用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. 队(queue),C++模板实现

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...