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. [原][OSG]整理osg渲染一帧的流程

    参考:最长的一帧 先看下frame void ViewerBase::frame(double simulationTime) { advance(simulationTime);//记录仿真时间,帧 ...

  2. 算法笔记--树的直径 && 树形dp && 虚树 && 树分治 && 树上差分 && 树链剖分

    树的直径: 利用了树的直径的一个性质:距某个点最远的叶子节点一定是树的某一条直径的端点. 先从任意一顶点a出发,bfs找到离它最远的一个叶子顶点b,然后再从b出发bfs找到离b最远的顶点c,那么b和c ...

  3. 原生js的博客

    原生js一里边还有很多二三等http://www.cnblogs.com/charling/p/3527561.html 选区器 http://wenku.baidu.com/link?url=zr2 ...

  4. JAVA反射会降低你的程序性能吗?

    原文出处 早两天写了<从把三千行代码重构成15行代码谈起>这篇文章,看到评论中有一些同学的回复还是在质疑反射的性能,好像程序用上了反射,就像开上了拖拉机似的.本来我觉得这个话题没有什么好讨 ...

  5. codeforces 555b//Case of Fugitive// Codeforces Round #310(Div. 1)

    题意:有n-1个缝隙,在上面搭桥,每个缝隙有个ll,rr值,ll<=长度<=rr的才能搭上去.求一种搭桥组合. 经典问题,应列入acm必背300题中.属于那种不可能自己想得出来的题.将二元 ...

  6. Spring Boot 介绍

    Spring Boot 能够让你更加容易创建一个独立启动,产品化的,并且是基于 Spring 的应用程序.我们为 Spring 平台及第三方库提供开箱即用的设置,这样你就可以有条不紊的开始开发,减少在 ...

  7. windows socket网络编程资料汇集

    windows socket网络基础详解(socket的流程介绍的很详细)http://blog.csdn.net/ithzhang/article/details/8448655 Windows S ...

  8. hdu-4023-博弈(模拟)

    Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submis ...

  9. 37. Sudoku Solver *HARD*

    Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...

  10. 1.strcpy使用注意

    void test1() { char string[10]; char *str1 ="0123456789"; strcpy(string,str1); } 上述代码问题? 字 ...