题意:现在有一个数写在黑板上,它以等概率转化为它的一个约数,可以是1,问经过k次转化后这个数的期望值

题解:如果这个数是一个素数的n次方,那么显然可以用动态规划来求这个数的答案,否则的话,就对每个素因数求答案,再相乘

参考博客:https://www.cnblogs.com/birchtree/p/10234203.html

ac代码:

#include<bits/stdc++.h>
#define ll long long
#define pa pair<int,int>
using namespace std;
const int maxn=100+10;
const int mod=1e9+7;
ll po[70],dp[10000+10][70];
int m;
ll qpow(ll x,ll n)
{
ll res=1,b=x;
while(n)
{
if(n&1)res=res*b%mod;
b=b*b%mod;
n/=2;
//cout<<<<endl;
}
return res;
}
ll solve(int a,ll b)
{
memset(dp,0,sizeof(dp));
dp[0][a]=1;
for(int i=1;i<=m;i++)
for(int j=0;j<=a;j++)
for(int k=j;k<=a;k++)
dp[i][j]=(dp[i][j]+dp[i-1][k]*po[k+1])%mod;
ll res=0;
for(int i=0;i<=a;i++)
res=(res+dp[m][i]*qpow(b,i)%mod)%mod;
return res;
}
int main()
{
ll ans=1,n;
for(int i=1;i<70;i++)
po[i]=qpow(i,mod-2);
scanf("%lld %d",&n,&m);
for(ll i=2;i*i<=n;i++)
{
if(n%i==0)
{
int k=0;
while(n%i==0)
{
//cout<<1<<endl;
k++;
n/=i;
}
ans=ans*solve(k,i)%mod;
}
}
if(n!=1)ans=ans*solve(1,n)%mod;
printf("%lld\n",ans);
return 0;
}

  

codeforces#1097 D. Makoto and a Blackboard(dp+期望)的更多相关文章

  1. 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 ...

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

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

  3. CF1097D Makoto and a Blackboard(期望)

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

  4. CF1097D Makoto and a Blackboard

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

  5. codeforces 1097 Hello 2019

    又回来了.. A - Gennady and a Card Game 好像没什么可说的了. #include<bits/stdc++.h> using namespace std; cha ...

  6. Codeforces 219D. Choosing Capital for Treeland (树dp)

    题目链接:http://codeforces.com/contest/219/problem/D 树dp //#pragma comment(linker, "/STACK:10240000 ...

  7. [CodeForces - 1272D] Remove One Element 【线性dp】

    [CodeForces - 1272D] Remove One Element [线性dp] 标签:题解 codeforces题解 dp 线性dp 题目描述 Time limit 2000 ms Me ...

  8. Codeforces 878 E. Numbers on the blackboard

    Codeforces 878 E. Numbers on the blackboard 解题思路 有一种最优策略是每次选择最后面一个大于等于 \(0\) 的元素进行合并,这样做完以后相当于给这个元素乘 ...

  9. D Makoto and a Blackboard

    Makoto and a Blackboard time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

随机推荐

  1. Windows下强制删除文件或文件夹(解除文件占用/Unlock)

    前言 在windows下,有时候会碰到一些文件无法删除,尽量使用“管理员取得所有权” ,但文件或文件夹依然无法删除,这一点非常苦恼. 本文记录几款可以解锁文件占用的软件. ProcessHacker ...

  2. Linux下键盘值 对应input_evnet的code值。

    最近做了一个linux下面的模拟鼠标和键盘的app,但不是很清楚字符对应的键值:查找内核源码,在kernel/include/uapi/linux/input.h文件中找到: 下面给出普通键盘上面对应 ...

  3. Vue 学习笔记之快速入门篇

    Vue (读音 /vjuː/,类似于 view) 是一套用于构建用户界面的渐进式框架.与其它大型框架不同的是,Vue 被设计为可以自底向上逐层应用.Vue 的核心库只关注视图层,不仅易于上手,还便于与 ...

  4. RPM包的版本号比较

    版本号表示格式为 epoch:version-release,例如 1:2-3 第一条原则是 rpm 属性优先级 epoch > version > release        两个 r ...

  5. kafka_2.11-2.0.0_安装部署

    参考博文:kafka 配置文件参数详解 参考博文:Kafka[第一篇]Kafka集群搭建 参考博文:如何为Kafka集群选择合适的Partitions数量 参考博文:Kafka Server.prop ...

  6. LeetCode算法题-Add Strings(Java实现)

    这是悦乐书的第223次更新,第236篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第90题(顺位题号是415).给定两个非负整数num1和num2表示为字符串,返回num ...

  7. 远程连接ubuntu的MongoDB遇到的坑

    首先连接不上,先查看云服务器上的安全组是否添加了对应的端口 如果打开了,那么久查看MongoDB是否允许远程连接 # mongod.conf # for documentation of all op ...

  8. 分布式消息中间件rocketmq的原理与实践

    RocketMQ作为阿里开源的一款高性能.高吞吐量的消息中间件,它是怎样来解决这两个问题的?RocketMQ 有哪些关键特性?其实现原理是怎样的? 关键特性以及其实现原理 一.顺序消息 消息有序指的是 ...

  9. nginx + uwsgi 部署 Django+Vue项目

    nginx + uwsgi 部署 Django+Vue项目 windows 本地 DNS 解析 文件路径 C:\Windows\System32\drivers\etc 单机本地测试运行方式,调用dj ...

  10. python抓取月光博客的全部文章而且依照标题分词存入mongodb中

    猛击这里:python抓取月光博客的全部文章