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_{r-1}(u)+f_{r-1}(v)}{2}$.
$q$组询问, 求$f_r(n)$的值模1e9+7.
显然可以得到$f_0(n)=2^{\omega(n)}$, 是积性函数.
所以$f_r=f_{r-1}*1$也为积性函数, 然后积性函数$dp$即可.
问题就转化为对每个素数$p$, 求$dp[p][r][k]=f_r(p^k)$.
$dp[p][r][k]=\sum\limits_{x=0}^k dp[p][r-1][x]$.
而$dp[p][0][k]=1$, 所以每个素数贡献相同, 只需要$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 = 1e6+10;
int dp[N][22], sum[N][22], mi[N]; int main() {
dp[0][0]=sum[0][0]=1;
REP(i,1,21) sum[0][i]=sum[0][i-1]+(dp[0][i]=2);
REP(i,1,N-1) {
dp[i][0]=sum[i][0]=1;
REP(j,1,21) sum[i][j]=(sum[i][j-1]+(dp[i][j]=sum[i-1][j]))%P;
}
REP(i,1,N-1) mi[i] = i;
REP(i,2,N-1) if (mi[i]==i) {
for (int j=i; j<N; j+=i) mi[j]=min(mi[j],i);
}
int q;
scanf("%d", &q);
while (q--) {
int r, n;
scanf("%d%d", &r, &n);
int ans = 1;
while (n!=1) {
int t = mi[n], k = 0;
while (n%t==0) n/=t, ++k;
ans = (ll)ans*dp[r][k]%P;
}
printf("%d\n", ans);
}
}
Bash Plays with Functions CodeForces - 757E (积性函数dp)的更多相关文章
- codeforces757E. Bash Plays with Functions(狄利克雷卷积 积性函数)
http://codeforces.com/contest/757/problem/E 题意 Sol 非常骚的一道题 首先把给的式子化一下,设$u = d$,那么$v = n / d$ $$f_r(n ...
- Makoto and a Blackboard CodeForces - 1097D (积性函数dp)
大意: 初始一个数字$n$, 每次操作随机变为$n$的一个因子, 求$k$次操作后的期望值. 设$n$经过$k$次操作后期望为$f_k(n)$. 就有$f_0(n)=n$, $f_k(n)=\frac ...
- Codeforces E. Bash Plays with Functions(积性函数DP)
链接 codeforces 题解 结论:\(f_0(n)=2^{n的质因子个数}\)= 根据性质可知\(f_0()\)是一个积性函数 对于\(f_{r+1}()\)化一下式子 对于 \[f_{r+1} ...
- 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 ...
- D. Makoto and a Blackboard(积性函数+DP)
题目链接:http://codeforces.com/contest/1097/problem/D 题目大意:给你n和k,每一次可以选取n的因子代替n,然后问你k次操作之后,每个因子的期望. 具体思路 ...
- 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)是积性函 ...
- CF 757E Bash Plays with Functions——积性函数+dp+质因数分解
题目:http://codeforces.com/contest/757/problem/E f0[n]=2^m,其中m是n的质因子个数(种类数).大概是一种质因数只能放在 d 或 n/d 两者之一. ...
- CF 757 E Bash Plays with Functions —— 积性函数与质因数分解
题目:http://codeforces.com/contest/757/problem/E 首先,f0(n)=2m,其中 m 是 n 的质因数的种类数: 而且 因为这个函数和1卷积,所以是一个积性函 ...
- 【codeforces 757E】Bash Plays with Functions
[题目链接]:http://codeforces.com/problemset/problem/757/E [题意] 给你q个询问; 每个询问包含r和n; 让你输出f[r][n]; 这里f[0][n] ...
随机推荐
- [题解] [AtCoder2134] Zigzag MST
题面 题解 考虑kruscal的过程 对于三个点\(x, y, x + 1\), 我们可以将\((x, y, z), (y, x + 1, z + 1)\)看做\((x, y, z), (x, x + ...
- UDP和TCP浅析
UDP协议全称是用户数据报协议,在网络中它与TCP协议一样用于处理数据包,是一种无连接的协议. 在选择使用协议的时候,选择UDP必须要谨慎.在网络质量令人十分不满意的环境下,UDP协议数据包丢失会比较 ...
- HBuilder开发MUI web app溢出页面上下无法滚动问题
因为没有对页面初始化,所以页面溢出部分不会显示,要解决此问题需要加上下面代码: JS代码: (function($){$(".mui-scroll-wrapper").scroll ...
- How to change the button text of <input type=“file” />?
How to change the button text of <input type=“file” />? Simply <label class="btn btn-p ...
- EvenBus源码分析
概述 一般使用EventBus的组件类,类似下面这种方式: public class SampleComponent extends Fragment { @Override public void ...
- 学习前端第一天心得体会(初步了解HTML5的新特性以及和HTML的区别)
一.HTML5是什么? HTML5 是最新的 HTML 标准. HTML5 是专门为承载丰富的 web 内容而设计的,并且无需额外插件. HTML5 拥有新的语义.图形以及多媒体元素. HTML5 提 ...
- TypeScript 编译目标(target)设置
TypeScript的编译配置文件tsconfig.json中有许多配置项,本文简单对比编译目标环境的配置项(target)的设置.模块(module)不在本文讨论之内,是另外一个大话题. 实验对于t ...
- Linux 查看操作系统版本信息 uname
Linux 查看操作系统版本信息 uname uname 命令用于显示当前系统的版本信息. 带 -a 选项的 uname 命令会给出当前操作系统的所有有用信息. 命令如下: [root@node1 / ...
- Eclipse使用高版本的jdk编译低版本的class文件的方法
如题,在这两天使用eclipse工具编译代码时,编译出来的class文件拿UE工具查看,版本为1.8版本的,而本地使用的tomcat版本是1.6的,运行中报错Unsupported major.min ...
- centos7安装VuePress
VuePress可以帮你快速建站,使用MarkDown语法生成静态html yum install -y gcc-c++ make curl -sL https://rpm.nodesource.co ...