题意:现在有一个数写在黑板上,它以等概率转化为它的一个约数,可以是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. Oracle根据已有表的数据建立新表

    需要保证create的表内的字段与select的表一致. create table 表名(字段名,字段名,字段名,字段名,字段名,字段名) as select * from 表名

  2. c/c++ 网络编程与多线程 编译参数

    网络编程与多线程 编译参数 编译时要链接操作系统的pthread库 g++ -g socket01.cpp -std=c++11 -pthread 不加-pthread的话,出现下面的错误: term ...

  3. 用好lua+unity,让性能飞起来——luajit集成篇/平台相关篇

    luajit集成篇 大家都知道luajit比原生lua快,快在jit这三个字上. 但实际情况是,luajit的行为十分复杂.尤其jit并不是一个简单的把代码翻译成机器码的机制,背后有很多会影响性能的因 ...

  4. java求解第N个素数(质数)

    面试中,遇到一个题目:求解第N个素数. import java.util.Scanner; public class GetPrimeNumber { public static int NthPri ...

  5. LeetCode算法题-Two Sum II - Input array is sorted

    这是悦乐书的第179次更新,第181篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第38题(顺位题号是167).给定已按升序排序的整数数组,找到两个数字,使它们相加到特定 ...

  6. 类中的 this关键字

    this可用于区分局部变量和成员变量,因为构造函数中如果使用 this.成员变量 = 参数值, 那么可以在new对象时,将初始化值赋值给成员变量,否则成员变量赋值失败, 所以this可以区分成员变量和 ...

  7. 英语进阶系列-A01-再别康桥

    每天必读知识 音标 发音网页 人称代词与物主代词 时态 朗读50遍词汇系列1 Number word 1 be 2 have 3 get 4 give 5 take 诗歌欣赏 [原诗] [英文版] 再 ...

  8. jsp页面无法使用EL

    解决:http://blog.csdn.net/caixiexin/article/details/6958199 在web.xml中头部引入,2.3版本不支持EL,2.4默认开启,2.5默认关闭需要 ...

  9. js中arguments详解

    在js中一切都是对象,连函数也是对象,函数名其实是引用函数定义对象的变量. 什么是arguments? 这个函数体内的arguments非常特殊,实际上是所在函数的一个内置类数组对象,可以用数组的[i ...

  10. [CQOI2016]手机号码

    嘟嘟嘟 这题一看就是数位dp. 我写数位dp,一般是按数位dp的格式写一个爆搜,然后加一点记忆化. 不过其实我一直不是很清楚记忆化是怎么加,感觉就是把dfs里的参数都扔到dp数组里,好像很暴力啊. 这 ...