大意: 初始一个数字$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. BitmapRegionDecoder

    Android加载大图——BitmapRegionDecoder(转)   BitmapRegionDecoder,从API10就引入了.如下图:   NPONRY0T35GE$13{254X8Z1. ...

  2. SSD 页、块、垃圾回收

    基本操作: 读出.写入.擦除: 因为NAND闪存单元的组织结构限制,单独读写一个闪存单元是不可能的.存储单元被组织起来并有着十分特别的属性.要知道这些属性对于为固态硬盘优化数据结构的过程和理解其行为来 ...

  3. [Python]在python中调用shell脚本,并传入参数-02python操作shell实例

    首先创建2个shell脚本文件,测试用. test_shell_no_para.sh 运行时,不需要传递参数 test_shell_2_para.sh 运行时,需要传递2个参数  test_shell ...

  4. Springboot获取resource的路径

    1.获取resource目录下的template路径 String path = Thread.currentThread().getContextClassLoader().getResource( ...

  5. Ironic 的 Rescue 救援模式实现流程

    目录 文章目录 目录 救援模式 实现 UML 图 救援模式 以往只有虚拟机支持救援模式,裸机是不支持的.直到 Queen 版本 Ironic 实现了这个功能.救援模式下,用户可以完成修复.Troubl ...

  6. JAVA记事本的图形用户界面应用程序

    JAVA记事本的图形用户界面应用程序 整体分析: 代码实现: import java.awt.EventQueue; import java.awt.event.ActionEvent; import ...

  7. Hadoop完全分布式安装配置完整过程

    一. 硬件.软件准备 1. 硬件设备 为了方便学习Hadoop,我采用了云服务器来配置Hadoop集群.集群使用三个节点,一个阿里云节点.一个腾讯云节点.一个华为云节点,其中阿里云和腾讯云都是通过使用 ...

  8. configmap使用-查看configmap个数

    [root@kube-node1 gitlab]# kubectl get cmNo resources found.

  9. 几种排序算法及Java实现排序的几种方式

    几种排序算法 下面的例子介绍了4种排序方法: 冒泡排序, 选择排序, 插入排序, 快速排序 package date201709.date20170915; public class SortUtil ...

  10. 实验一 part2

    #include <stdio.h> int main () { int x; printf("输入一个整数:\n"); scanf("%d",&a ...