题意

题目链接

Sol

首先考虑当\(n = p^x\),其中\(p\)是质数,显然它的因子只有\(1, p, p^2, \dots p^x\)(最多logn个)

那么可以直接dp, 设\(f[i][j]\)表示经过了\(i\)轮,当前数是\(p^j\)的概率,转移的时候枚举这一轮的\(p^j\)转移一下

然后我们可以把每个质因子分开算,最后乘起来就好了

至于这样为什么是对的。(开始瞎扯),考虑最后的每个约数,它一定是一堆质因子的乘积,而每个质因子的概率我们是知道的,所以这样乘起来算是没问题的。

其实本质上还是因为约数和/个数都是积性函数

时间复杂度:\(O(\sqrt{n} + k log^2 n)\)

#include<bits/stdc++.h>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
#define int long long
#define LL long long
#define Fin(x) {freopen(#x".in","r",stdin);}
#define Fout(x) {freopen(#x".out","w",stdout);}
using namespace std;
const int MAXN = 1e6 + 10, mod = 1e9 + 7, INF = 1e9 + 10;
const double eps = 1e-9;
template <typename A, typename B> inline bool chmin(A &a, B b){if(a > b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline bool chmax(A &a, B b){if(a < b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline LL add(A x, B y) {if(x + y < 0) return x + y + mod; return x + y >= mod ? x + y - mod : x + y;}
template <typename A, typename B> inline void add2(A &x, B y) {if(x + y < 0) x = x + y + mod; else x = (x + y >= mod ? x + y - mod : x + y);}
template <typename A, typename B> inline LL mul(A x, B y) {return 1ll * x * y % mod;}
template <typename A, typename B> inline void mul2(A &x, B y) {x = (1ll * x * y % mod + mod) % mod;}
template <typename A> inline void debug(A a){cout << a << '\n';}
template <typename A> inline LL sqr(A x){return 1ll * x * x;}
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, K, top, inv[MAXN];
Pair st[MAXN];
int f[10001][1001];
int fp(int a, int p) {
int base = 1;
while(p) {
if(p & 1) base = mul(base, a);
a = mul(a, a); p >>= 1;
}
return base;
}
int solve(int a, int b) {//a^b
memset(f, 0, sizeof(f));
f[0][b] = 1;
for(int i = 1; i <= K; i++)
for(int j = 0; j <= b; j++)
for(int k = j; k <= b; k++)
add2(f[i][j], mul(f[i - 1][k], inv[k + 1]));
int res = 0;
for(int i = 0; i <= b; i++) add2(res, mul(f[K][i], fp(a, i)));
return res;
}
signed main() {
for(int i = 1; i <= 666; i++) inv[i] = fp(i, mod - 2);
cin >> N >> K;
for(int i = 2; i * i <= N; i++) {
if(!(N % i)) {
st[++top] = MP(i, 0);
while(!(N % i)) st[top].se++, N /= i;
}
}
if(N) st[++top] = MP(N, 1);
int ans = 1;
for(int i = 1; i <= top; i++)
ans = mul(ans, solve(st[i].fi, st[i].se));
cout << ans;
return 0;
}
/*
2
(()))
(
*/

cf1097D. Makoto and a Blackboard(期望dp)的更多相关文章

  1. CF1097D Makoto and a Blackboard(期望)

    link 题目大意:给您一个数 n, 每次从n的所有约数(包含1.n)中等概率选出一个约数替换n,重复操作k次,求最后结果期望值%1e9+7. 题解:考虑暴力,我们设f(n,k)代表答案,则有f(n, ...

  2. CF1097D Makoto and a Blackboard

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

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

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

  4. CF1097D Makoto and a Blackboard(期望)

    [Luogu-CF1097D] 给定 \(n,k\)一共会进行 \(k\) 次操作 , 每次操作会把 \(n\) 等概率的变成 \(n\) 的某个约数 求操作 \(k\) 次后 \(n\) 的期望是多 ...

  5. CF1097D Makoto and a Blackboard 质因数分解 DP

    Hello 2019 D 题意: 给定一个n,每次随机把n换成它的因数,问经过k次操作,最终的结果的期望. 思路: 一个数可以表示为质数的幂次的积.所以对于这个数,我们可以分别讨论他的质因子的情况. ...

  6. codeforces#1097 D. Makoto and a Blackboard(dp+期望)

    题意:现在有一个数写在黑板上,它以等概率转化为它的一个约数,可以是1,问经过k次转化后这个数的期望值 题解:如果这个数是一个素数的n次方,那么显然可以用动态规划来求这个数的答案,否则的话,就对每个素因 ...

  7. codeforces1097D Makoto and a Blackboard 数学+期望dp

    题目传送门 题目大意: 给出一个n和k,每次操作可以把n等概率的变成自己的某一个因数,(6可以变成1,2,3,6,并且概率相等),问经过k次操作后,期望是多少? 思路:数学和期望dp  好题好题!! ...

  8. 【BZOJ-1419】Red is good 概率期望DP

    1419: Red is good Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 660  Solved: 257[Submit][Status][Di ...

  9. [NOIP2016]换教室 D1 T3 Floyed+期望DP

    [NOIP2016]换教室 D1 T3 Description 对于刚上大学的牛牛来说, 他面临的第一个问题是如何根据实际情况中情合适的课程. 在可以选择的课程中,有2n节课程安排在n个时间段上.在第 ...

随机推荐

  1. Zookeeper原理分析之存储结构ZkDatabase

    ZKDatabase在内存中维护了zookeeper的sessions, datatree和commit logs集合. 当zookeeper server启动的时候会将txnlogs和snapsho ...

  2. 为什么有监听socket和连接socket,为什么产生两个socket

    为什么有监听socket和连接socket,为什么产生两个socket 先看一半的socket建立连接的双方的过程: 客户端: socket()---->创建出 active_socket_fd ...

  3. 手机端API接口验证及参数签名验证

    问题背景: 后端服务对手机APP端开放API,没有基本的校验就是裸奔,别人抓取接口后容易恶意请求,不要求严格的做的安全,但是简单的基础安全屏障是要建立的,再配合HTTPS使用,这样使后端服务尽可能的安 ...

  4. fullpage.js与animate.css搭配使用

    jquery的fullpage.js插件的使用 https://alvarotrigo.com/fullPage/#3rdPage   官网 https://github.com/alvarotrig ...

  5. django 高级

    1.使用form: django的form提供了统一的结构化的后台验证机制,错误信息,也容易展现在前台界面上.由于python的面向对象,使得编写html也能够代码复用. a.多个field 综合验证 ...

  6. 1301班 github安装及账户注册

    1.下载github 下载地址: http://git-scm.com/download/ 2.账号注册 进入:mukever.online 在右下角的“New user? Create an acc ...

  7. 开源视频会议bigbluebutton

    这是另一个开源视频会议项目,简称bbb 官方网站:http://bigbluebutton.org/ 代码地址:https://code.google.com/p/bigbluebutton/ dem ...

  8. 【数组】Remove Duplicates from Sorted Array II

    题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For ex ...

  9. lower类的accessCode解读

    /** Access codes for dereferencing(解引用), assignment, * and pre/post increment/decrement. * Access co ...

  10. 关于符号Symbol第二篇

    来看一下继承自Symbol的具体实现类. 1.TypeSymbol /** A class for type symbols. * Type variables are represented by ...