CF 1097D - Hello 2019 D题: Makoto and a Blackboard
(有任何问题欢迎留言或私聊 && 欢迎交流讨论哦
Catalog
Problem:传送门
原题目描述在最下面。
给一个数n,由k次操作。每次操作等概率的把n变成他的一个因数(\(1\leq x\leq n\)),问k次操作后得到的数的期望是多少。
Solution:
\(n = p1^{a1}*...*pm^{am}\)
积性函数: \(fk(n) = fk(p1^{a1})*...*fk(pm^{am})\)
\(dp[j]\) 表示\(pi^j\)执行\(k\)次操作之后的结果的期望
\(dp[j] = sigma(dp[j-1])/yinzi\_num\)
\(yinzi\_num = j+1\)
AC_Code:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MXN = 1e6 + 7;
const int INF = 0x3f3f3f3f;
const LL mod = 1000000007;
const LL MOD = 5631653553151;
LL n;
int k;
LL inv[MXN];
LL calc(LL x, int p) {
std::vector<LL> dp(p+1);
dp[0] = 1;
for(int i = 1; i <= p; ++i) {
dp[i] = dp[i-1] * x % mod;
}
for(int t = 0; t < k; ++t) {
for(int i = 1; i <= p; ++i) dp[i] = (dp[i-1]+dp[i]) % mod;
for(int i = 1; i <= p; ++i) dp[i] = dp[i] * inv[i+1] % mod;
}
return dp[p];
}
int main() {
inv[1] = 1;
for(int i = 2; i < MXN; ++i) inv[i] = inv[mod%i]*(mod-mod/i)%mod;
scanf("%lld%d", &n, &k);
LL tn = n, ans = 1;
int cnt;
for(LL i = 2; i * i <= n; ++i) {
if(tn % i == 0) {
cnt = 0;
while(tn % i == 0) tn /= i, ++ cnt;
ans *= calc(i, cnt);
//printf("%lld %d\n", i, cnt);
if(ans >= mod) ans %= mod;
}
if(tn == 1) break;
}
if(tn > 1) {
ans *= calc(tn, 1);
}
printf("%lld\n", ans % mod);
return 0;
}
Problem Description:
CF 1097D - Hello 2019 D题: Makoto and a Blackboard的更多相关文章
- CF 628B New Skateboard --- 水题
CD 628B 题目大意:给定一个数字(<=3*10^5),判断其能被4整除的连续子串有多少个 解题思路:注意一个整除4的性质: 若bc能被4整除,则a1a2a3a4...anbc也一定能被4整 ...
- CF 628A --- Tennis Tournament --- 水题
CF 628A 题目大意:给定n,b,p,其中n为进行比赛的人数,b为每场进行比赛的每一位运动员需要的水的数量, p为整个赛程提供给每位运动员的毛巾数量, 每次在剩余的n人数中,挑选2^k=m(m & ...
- D Makoto and a Blackboard
Makoto and a Blackboard time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- CF1097D Makoto and a Blackboard
题目地址:CF1097D Makoto and a Blackboard 首先考虑 \(n=p^c\) ( \(p\) 为质数)的情况,显然DP: 令 \(f_{i,j}\) 为第 \(i\) 次替换 ...
- CF 1097D Makoto and a Blackboard
算是记一下昨天晚上都想了些什么 官方题解 点我 简单题意 给定两个正整数$n$和$k$,定义一步操作为把当前的数字$n$等概率地变成$n$的任何一个约数,求$k$步操作后的期望数字,模$1e9 + ...
- CF #636 (Div. 3) 对应题号CF1343
unrated 选手悠闲做题,然后只做出四个滚蛋了 符合 div3 一贯风格,没啥难算法 E最后就要调出来了,但还是赛后才A的 CF1343A Candies 传送门 找到一个 \(x\),使得存在一 ...
- Yahoo Programming Contest 2019 补题记录(DEF)
D - Ears 题目链接:D - Ears 大意:你在一个\(0-L\)的数轴上行走,从整数格出发,在整数格结束,可以在整数格转弯.每当你经过坐标为\(i-0.5\)的位置时(\(i\)是整数),在 ...
- CodeForces - 1097D:Makoto and a Blackboard (积性)
Makoto has a big blackboard with a positive integer n written on it. He will perform the following a ...
- ACM/ICPC Moscow Prefinal 2019 趣题记录
### Day1: ### **Problem C:** 设$k_i$为$[A, B]$中二进制第$i$位是1的数的个数. 给出$k_0 \cdots k_{63}$, 求出$[A, B]$ ...
随机推荐
- mysql学习-explain
表头包含有: id---select_type---table---type---possible_keys---key---key_len---ref---rows---Extra id:selec ...
- 【软工项目Beta阶段】绝不划水队OUC-Market版本测试报告
我们在开发APP的时候进行了软件的测试,同时发现了一些BUG,如下: bug 我的:与各种页面之间的交互不灵活 登录与注册:记住密码功能不完善 商场主界面:搜索功能还没有完善 收藏功能:与数据库的交互 ...
- $router和router区别
this.$router.push({path:'/'})//这个是js编程式的一种动态跳转路由方式,是全局的路由对象. 而写在router声明文件中的router是自己定义实例化的一个对象.可以使用 ...
- 20175223 MySQL
目录 完成结果 要求 1 :导入world.sql 要求 2 :CityWanna.java CityWanna.java 要求 3 :CountryWanna.java CountryWanna.j ...
- 个人笔记 - Word2013 论文格式调整
1.如何实现每章奇偶页页眉不同 2.参考文献自动编号.交叉引用及在正文中自动更新 <1>在要插入引用上标的地方点击“插入”——>“交叉引用” <2>设置引用类型为“编号项 ...
- C++——class类和struct结构体的唯一区别
唯一的区别:默认访问权限不同,其他没有任何区别. class Base{/****/}; class D1:Base{/****/};//默认D1对Base是public继承 struct D2:Ba ...
- idea sevlet连sqlserver失败解决
1 普通java程序连sqlserver失败解决办法:https://www.cnblogs.com/Demonfeatuing/p/9208514.html 出现javax.xml.bind.J ...
- Git与GitHub同步
如何通过Git Bash实现本地与远端仓库——GitHub的同步 1.下载安装Git:下载网址 2.在自己的github上新建一个repository 例如我这里新建了一个叫test的reposito ...
- Pandas DataFrame操作
DataFrame的创建 >>> import pandas as pd >>> from pandas import DataFrame #define a di ...
- composer 配置镜像
阿里云镜像:composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ 腾讯云镜像:composer ...