大意: 初始一个数字$n$, 每次操作随机变为$n$的一个因子, 求$k$次操作后的期望值.

设$n$经过$k$次操作后期望为$f_k(n)$.

就有$f_0(n)=n$, $f_k(n)=\frac{\sum\limits_{d|n}{f_{k-1}(d)}}{\sigma_0(n)}, k>0$.

显然$f_k(n)$为积性函数, $dp$算出每个素因子的贡献即可.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 1e4+10;
int dp[N][70], sum[N][70], mi[N]; int DP(int p, int k, int r) {
memset(dp,0,sizeof dp);
memset(sum,0,sizeof sum);
sum[0][0] = dp[0][0] = 1;
REP(i,1,k) sum[0][i]=(sum[0][i-1]+(dp[0][i]=(ll)dp[0][i-1]*p%P))%P;
REP(i,1,r) {
sum[i][0] = dp[i][0] = 1;
REP(j,1,k) sum[i][j]=(sum[i][j-1]+(dp[i][j]=sum[i-1][j]*inv(j+1)%P))%P;
}
return dp[r][k];
} int main() {
int k;
ll n;
scanf("%lld%d", &n, &k);
int mx = sqrt(n+0.5), ans = 1;
REP(i,2,mx) if (n%i==0) {
int x = 0;
while (n%i==0) n/=i, ++x;
ans = (ll)ans*DP(i,x,k)%P;
}
if (n>1) ans = (ll)ans*DP(n%P,1,k)%P;
if (ans<0) ans+=P;
printf("%d\n", ans);
}

Makoto and a Blackboard CodeForces - 1097D (积性函数dp)的更多相关文章

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

  2. D. Makoto and a Blackboard(积性函数+DP)

    题目链接:http://codeforces.com/contest/1097/problem/D 题目大意:给你n和k,每一次可以选取n的因子代替n,然后问你k次操作之后,每个因子的期望. 具体思路 ...

  3. Codeforces E. Bash Plays with Functions(积性函数DP)

    链接 codeforces 题解 结论:\(f_0(n)=2^{n的质因子个数}\)= 根据性质可知\(f_0()\)是一个积性函数 对于\(f_{r+1}()\)化一下式子 对于 \[f_{r+1} ...

  4. Codeforces757E.Bash Plays With Functions(积性函数 DP)

    题目链接 \(Description\) q次询问,每次给定r,n,求\(F_r(n)\). \[ f_0(n)=\sum_{u\times v=n}[(u,v)=1]\\ f_{r+1}(n)=\s ...

  5. Problem : 这个题如果不是签到题 Asm.Def就女装(积性函数dp

    https://oj.neu.edu.cn/problem/1460 思路:若n=(p1^a1)*(p2^a2)...(pn^an),则f(n,0)=a1*a2*...*an,显然f(n,0)是积性函 ...

  6. CF 757E Bash Plays with Functions——积性函数+dp+质因数分解

    题目:http://codeforces.com/contest/757/problem/E f0[n]=2^m,其中m是n的质因子个数(种类数).大概是一种质因数只能放在 d 或 n/d 两者之一. ...

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

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

  8. codeforces757E. Bash Plays with Functions(狄利克雷卷积 积性函数)

    http://codeforces.com/contest/757/problem/E 题意 Sol 非常骚的一道题 首先把给的式子化一下,设$u = d$,那么$v = n / d$ $$f_r(n ...

  9. CF 757 E Bash Plays with Functions —— 积性函数与质因数分解

    题目:http://codeforces.com/contest/757/problem/E 首先,f0(n)=2m,其中 m 是 n 的质因数的种类数: 而且 因为这个函数和1卷积,所以是一个积性函 ...

随机推荐

  1. 2.6.2 XML配置:使用testNG进行并发多浏览器测试

    测试类 1 @Parameters("browser") 定义browser参数. 在测试执行过程中,browser参数具体值由XML文件进行传递. 1 2 3 4 5 6 7 8 ...

  2. 【译】OkHttp3 拦截器(Interceptor)

    一,OkHttp 拦截器介绍(译自官方文档) 官方文档:https://github.com/square/okhttp/wiki/Interceptors 拦截器是 OkHttp 提供的对 Http ...

  3. Spring常用的jar+普通构造注入

    常用工具 jar 说明 提供AOP(面向切面编程)实现:spring -aop spring提供对AspectJ框架的整合:spring-aspects 提供 IoC(控制反转)的基础实现:sprin ...

  4. SRS之RTMP handshake

    1. SrsRtmpServer::handshake 位于 srs_rtmp_stack.cpp. int SrsRtmpServer::handshake() { int ret = ERROR_ ...

  5. 用python绘制趋势图

    import matplotlib.pyplot as plt #plt用于显示图片 import matplotlib.image as mping #mping用于读取图片 import date ...

  6. OpenCV学习笔记(13)——轮廓特征

    查找轮廓的不同特征,例如面积,周长,重心,边界等 1.矩 图像的矩可以帮助我们计算图像的质心,面积等. 函数cv2.momen()会将计算得到的矩以一个字典的形式返回, 我们的测试图像如下: 例程如下 ...

  7. Linux 服务器基本优化

    一:修改ulimit数 vi /etc/security/limits.conf 添加如下行: * soft noproc 65535 * hard noproc 65535 * soft nofil ...

  8. Linux ospf+lvs

    待更新... https://my.oschina.net/lxcong/blog/143904?p=2&temp=1469345328746

  9. Eclipse 设置护眼背景色

    Eclipse 设置护眼背景色 1.设置字体大小 Window --> Preferences --> General --> Apprearance --> Colors a ...

  10. MongoDB数据库数据清理

    清理MongoDB集群数据: 1.登录MongoDB集群(mongos): # mongo -u username -p password --authenticationDatabase admin ...