Codeforces E. Bash Plays with Functions(积性函数DP)
链接
题解
结论:\(f_0(n)=2^{n的质因子个数}\)=
根据性质可知\(f_0()\)是一个积性函数
对于\(f_{r+1}()\)化一下式子
对于
\]
\(f_r+1\)可以看做\(f_r()\)和\(g(d)\)的狄利克雷卷积因为\(f_0()\)是积性函数,\(g(d)\)也是积性函数,由卷积性质得\(f_{r+1}()\)也是积性函数,那么\(f_r\)同理
对于\(n\)质因数分解得到:
\]
那么:
\]
对于\(p_i^{e_i}\)的所有因子个数为\(p^{ \{0,1,2,\cdots e_i \} }\)
可以看出,质因子的因字数时与\(p\)无关的
然后就可以dp预处理出,在\(f_i\)中i中的\(e\)次方的函数值
用f[i][j]表示\(f_i(p^j)\)那么f[i][j]=\(\sum_{k=0}^{j} dp[i-1][k]\)
代码
#include<cstdio>
#include<cmath>
#include<iostream>
int Q;
const int maxn = 10001;
const int mod = 1e9+7;
inline int read() {
int x=0;char c=getchar();
while(c<'0'||c>'9') c=getchar();
while(c<='9'&&c>='0')x=x*10+c-'0',c=getchar();
return x;
}
int prime[maxn],num=0;
bool vis[maxn];
int f[maxn*100][22];
void init() {
for(int i=2;i<=maxn;++i) {
if(!vis[i]) prime[++num]=i;
for(int j=1;j<=num&&i*prime[j]<maxn;++j) {
vis[i*prime[j]]=1;
if(!(i%prime[j]))break;
}
}
for(int i=1;i<=20;++i) f[0][i]=2;f[0][0]=1;
for(int sum=0,i=1;i<=maxn*100;++i) {
for(int j=0;j<=20;++j) {
sum+=f[i-1][j];sum%=mod;
f[i][j]+=sum;f[i][j]%=mod;
}
sum=0;
}
}
int solve(int a,int b) {
int ans=1;int st=sqrt(b)+0.5;
for(int cnt=0,i=1;i<=num&&prime[i]<=st;++i) {
cnt=0;
while(!(b%prime[i]))cnt++,b/=prime[i];
ans=(1LL*ans*f[a][cnt])%mod;
}
if(b>1)ans=(1LL*ans*f[a][1])%mod;
printf("%d\n",ans);
}
int main() {
init();
Q=read();
for(int a,b;Q--;) {
a=read();b=read();
solve(a,b);
}
return 0;
}
Codeforces E. Bash Plays with Functions(积性函数DP)的更多相关文章
- 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 ...
- 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卷积,所以是一个积性函 ...
- 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 ...
- Makoto and a Blackboard CodeForces - 1097D (积性函数dp)
大意: 初始一个数字$n$, 每次操作随机变为$n$的一个因子, 求$k$次操作后的期望值. 设$n$经过$k$次操作后期望为$f_k(n)$. 就有$f_0(n)=n$, $f_k(n)=\frac ...
- [Codeforces 757E] Bash Plays with Functions (数论)
题目链接: http://codeforces.com/contest/757/problem/E?csrf_token=f6c272cce871728ac1c239c34006ae90 题目: 题解 ...
- 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)是积性函 ...
- codeforces757E. Bash Plays with Functions(狄利克雷卷积 积性函数)
http://codeforces.com/contest/757/problem/E 题意 Sol 非常骚的一道题 首先把给的式子化一下,设$u = d$,那么$v = n / d$ $$f_r(n ...
随机推荐
- 不吹不擂,你想要的Python面试都在这里了【315+道题】+精心整理的解答
Part01-Py基础篇(80) Part02-网络编程和并发(34) Part03-数据库和缓存(46) Part04-前端框架和其他(155) Part01-Py基础篇(80) 1.为什么学习Py ...
- python学习总结----时间模块 and 虚拟环境(了解)
time - sleep:休眠指定的秒数(可以是小数) - time:获取时间戳 # 获取时间戳(从1970-01-01 00:00:00到此刻的秒数) t = time.time() print(t ...
- sources.list
deb http://debian.ustc.edu.cn/ubuntu/ precise main multiverse restricted universe deb http://debian. ...
- 批量部署ssh免密登陆
#!/bin/bash#set -xservers="10.254.192.xx10.254.192.xx10.254.192.xx"passwd="xxxxxxxx&q ...
- UVa 1445 - Cubist Artwork
统计正面看高度为i的竖条个数为cnt1[i], 统计侧面看高度为i的竖条个数为cnt2[i]: ans = sum( i * max( cnt1[i], cnt2[i] ) ); ( 1 <= ...
- jquery serialize() 方法
ajax异步提交的时候,会使用该方法. 方法:jQuery ajax - serialize() 方法
- windows 10 change default program bug
windows 10 change default program bug https://www.isumsoft.com/windows-10/how-to-change-or-set-defau ...
- [poj] 3977 Subset || 折半搜索MITM
原题 给定N个整数组成的数列(N<=35),从中选出一个子集,使得这个子集的所有元素的值的和的绝对值最小,如果有多组数据满足的话,选择子集元素最少的那个. n<=35,所以双向dfs的O( ...
- Batting Practice LightOJ - 1408
Batting Practice LightOJ - 1408(概率dp) 题意:有无限个球,进球的概率为p,问你连续不进k1个球或者连续进k2个球需要使用的球的个数的期望 思路: \(定义f[i]表 ...
- GDB调试——经验总结
GDB调试的一些很有用经验: 1. gdb调试,如果有参数,可以在run命令后加,也可以使用set args :如果是使用gdbserver+gdb的远程调试方式,参数可以在gdbserver后面加. ...