CodeForces - 1097D:Makoto and a Blackboard (积性)
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
6 1
3
6 2
875000008
60 5
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 (积性)的更多相关文章
- CF1097D Makoto and a Blackboard 积性函数、概率期望、DP
传送门 比赛秒写完ABC结果不会D--最后C还fst了qwq 首先可以想到一个约数个数\(^2\)乘上\(K\)的暴力DP,但是显然会被卡 在\(10^{15}\)范围内因数最多的数是\(978217 ...
- Codeforces 1097D. Makoto and a Blackboard
传送门 首先考虑如果 $n$ 只有一个质因数的情况,即 $n=p^t$ 那么显然可以 $dp$ ,设 $f[i][j]$ 表示第 $i$ 步,当前剩下 $p^j$ 的概率 那么转移很简单: $f[i] ...
- Codeforces E. Bash Plays with Functions(积性函数DP)
链接 codeforces 题解 结论:\(f_0(n)=2^{n的质因子个数}\)= 根据性质可知\(f_0()\)是一个积性函数 对于\(f_{r+1}()\)化一下式子 对于 \[f_{r+1} ...
- CF 1097D Makoto and a Blackboard
算是记一下昨天晚上都想了些什么 官方题解 点我 简单题意 给定两个正整数$n$和$k$,定义一步操作为把当前的数字$n$等概率地变成$n$的任何一个约数,求$k$步操作后的期望数字,模$1e9 + ...
- Makoto and a Blackboard CodeForces - 1097D (积性函数dp)
大意: 初始一个数字$n$, 每次操作随机变为$n$的一个因子, 求$k$次操作后的期望值. 设$n$经过$k$次操作后期望为$f_k(n)$. 就有$f_0(n)=n$, $f_k(n)=\frac ...
- D. Makoto and a Blackboard(积性函数+DP)
题目链接:http://codeforces.com/contest/1097/problem/D 题目大意:给你n和k,每一次可以选取n的因子代替n,然后问你k次操作之后,每个因子的期望. 具体思路 ...
- 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 ...
- CF 1097D - Hello 2019 D题: Makoto and a Blackboard
目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:传送门 Portal 原题目描述在最下面. 给一个数n ...
- CF1097D Makoto and a Blackboard
题目地址:CF1097D Makoto and a Blackboard 首先考虑 \(n=p^c\) ( \(p\) 为质数)的情况,显然DP: 令 \(f_{i,j}\) 为第 \(i\) 次替换 ...
- codeforces757E. Bash Plays with Functions(狄利克雷卷积 积性函数)
http://codeforces.com/contest/757/problem/E 题意 Sol 非常骚的一道题 首先把给的式子化一下,设$u = d$,那么$v = n / d$ $$f_r(n ...
随机推荐
- Selenium库的使用
一.什么是Selenium selenium 是一套完整的web应用程序测试系统,包含了测试的录制(selenium IDE),编写及运行(Selenium Remote Control)和测试的并行 ...
- 最大交换 Maximum Swap
2018-07-28 16:52:20 问题描述: 问题求解: 使用bucket数组来记录每个数最后出现的位置,然后从左向右遍历一遍即可. public int maximumSwap(int num ...
- Hibernate入门第二课 Hibernate Tools for Eclipse Plugins安装
Hibernate入门第二课 Hibernate Tools for Eclipse Plugins安装 你们可以直接去,http://blog.csdn.net/wei_chong_chong/ar ...
- String字符串存入数据库中超出最大长度(oracle varchar2 4000)?应合理分条存储(java实现-工具/方法)
问题描述 需要向数据库中保存数据,但某个字段内容长度过长(有中文.符号.英文),应该根据字符串内容与数据库存储上限合理设置储存方式. 解决思路 分条存储,即多条数据前n个字段一致,最后内容字段不同,下 ...
- LeetCode--225--用队列实现栈
问题描述: 使用队列实现栈的下列操作: push(x) -- 元素 x 入栈 pop() -- 移除栈顶元素 top() -- 获取栈顶元素 empty() -- 返回栈是否为空 注意: 你只能使用队 ...
- kmp练习
kmp板子如下, 失配数组不优化的话, $f_i$就表示子串[0...i]前后缀最大匹配长度 int main() { scanf("%s%s", t, p); int n = s ...
- LICEcap 和 FS Capture入门教程
上一篇介绍了如何使用 Visio 图形图表工具,文中贴了一张gif图,留言的小伙伴们迫不及待想知道如何录制 GIF 图,强哥姑且卖弄一次,把 PC 端截图工具和教程分享给大家,分别为 LICEcap ...
- 常见MIME类型例表
常见MIME类型例表: 序号 内容类型 文件扩展名 描述 1 application/msword doc Microsoft Word 2 application/octet-stream bin ...
- es-hadoop saveToEsWithMeta
@Test def testEsRDDWriteWithDynamicMapping() { val doc1 = Map("one" -> null, "two& ...
- 微信小程序--登录流程梳理
前言 微信小程序凡是需要记录用户信息都需要登录,但是也有几种不同的登录方式,但是在小程序部分的登录流程是一样的.之前就朦朦胧胧地用之前项目的逻辑改改直接用了,这个新项目要用就又结合官方文档重新梳理了下 ...