http://codeforces.com/contest/757/problem/E

题意

Sol

非常骚的一道题

首先把给的式子化一下,设$u = d$,那么$v = n / d$

$$f_r(n) = \sum_{d \mid n} \frac{f_{r - 1}(d) + f_{r - 1}(\frac{n}{d})}{2}$$

$$= \sum_{d\mid n} f_{r - 1}(d)$$

很显然,这是$f_r(n)$与$1$的狄利克雷卷积

根据归纳法可以证明$f_r(n)$为积性函数

我们可以对每个质因子分别考虑他们的贡献

考虑$f_0(p^k) = [k =0]+1$,与$p$是无关的,因此我们只要枚举$r$和$k$就好

$f_r(p^k) = \sum_{i = 0}^k f_{r - 1}(p^i)$

前缀和优化dp

#include<cstdio>
#include<cmath>
#define LL long long
using namespace std;
const int MAXN = 1e6 + , INF = 1e9 + , mod = 1e9 + ;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int prime[MAXN], tot, vis[MAXN];
LL f[MAXN][];
void GetPrime(int N) {
for(int i = ; i <= N; i++) {
if(!vis[i]) prime[++tot] = i;
for(int j = ; j <= N && i * prime[j] <= N; j++) {
vis[i * prime[j]] = ;
if(i % prime[j] == ) break;
}
}
}
void Pre(int N, int M) {
f[][] = ;//f[i][k] f_r(p^k)
for(int i = ; i <= M; i++) f[][i] = ;
for(int r = ; r <= N; r++) {
LL sum = ;
for(int k = ; k <= M; k++) {
sum += f[r - ][k];
(f[r][k] += sum ) %= mod;
}
}
}
main() {
GetPrime(1e6 + );
Pre(1e6 + , );
int Q = read();
while(Q--) {
int r = read(), n = read();
LL ans = ;
for(int i = ; i <= tot && prime[i] <= sqrt(n); i++) {
if(n % prime[i]) continue;
int num = ;
while(!(n % prime[i])) num++, n /= prime[i];
ans = 1ll * ans * (f[r][num]) % mod;
}
if(n > ) ans = (1ll * ans * f[r][]) % mod;
printf("%I64d\n", ans);
}
}
/* */

codeforces757E. Bash Plays with Functions(狄利克雷卷积 积性函数)的更多相关文章

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

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

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

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

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

  5. Codeforces 757 E Bash Plays with Functions

    Discription Bash got tired on his journey to become the greatest Pokemon master. So he decides to ta ...

  6. CF757E Bash Plays with Functions

    题解 q<=1e6,询问非常多.而n,r也很大,必须要预处理所有的答案,询问的时候,能比较快速地查询. 离线也是没有什么意义的,因为必须递推. 先翻译$f_0(n)$ $f_0(n)=\sum_ ...

  7. Master of Phi (欧拉函数 + 积性函数的性质 + 狄利克雷卷积)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6265 题目大意:首先T是测试组数,n代表当前这个数的因子的种类,然后接下来的p和q,代表当前这个数的因 ...

  8. 【codeforces 757E】Bash Plays with Functions

    [题目链接]:http://codeforces.com/problemset/problem/757/E [题意] 给你q个询问; 每个询问包含r和n; 让你输出f[r][n]; 这里f[0][n] ...

  9. [Codeforces 757E] Bash Plays with Functions (数论)

    题目链接: http://codeforces.com/contest/757/problem/E?csrf_token=f6c272cce871728ac1c239c34006ae90 题目: 题解 ...

随机推荐

  1. [转]理解js中的原型链,prototype与__proto__的关系

    本文转自:http://rockyuse.iteye.com/blog/1426510 说到prototype,就不得不先说下new的过程. 我们先看看这样一段代码: 1 <script typ ...

  2. Python3实现计算BMI指数,跟我一起来计算你的BMI吧

    废话不多说,直接上程序哈: name=input('Name:') height=input('Height(m):') weight=input('Weight(kg):') BMI=float(f ...

  3. android 官网访问不了

    网上搜到的解决方案,亲测有用.记下来,以备遗忘. 使用管理员权限,修改C:\Windows\System32\Drivers\etc\hosts文件,加入以下内容 173.194.127.7 deve ...

  4. Graphics绘制类及打印机设置相关

    Graphics 有两个多个方法 这里面介绍3个: 1.Graphics.drawString():绘制.画字符串........... e.Graphics.DrawString("新乡市 ...

  5. ThinkPHP find大坑 不要随便用

    举例: M("User")->find(3); $m=M("User"); $m->userName="aaa"; $m-> ...

  6. Spring课程 Spring入门篇 3-4 Spring bean装配(上)之自动装配

    课程链接: 1 自动装配的方式 2 自动装配实现 1 自动装配的方式 根据反射的机制 1.1 byName根据属性名自动装配,类似于依赖注入的set注入.(如果找不到set属性中的bean,如果tes ...

  7. vue ------ 安装和引入

    Vue.js 的官网上直接下载 vue.min.js 并用 <script> 标签引入.: http://vuejs.org/js/vue.min.js 以下推荐国外比较稳定的两个 CDN ...

  8. Java设计模式—模板方法模式

    模板方法模式仅仅使用了Java的继承机制,但它是一个应用非常广泛的模式. 1.定义:           一个操作中的算法的框架,而将一些步骤延迟到子类中.使得子类可以不改变一个算法的结构即可重定义该 ...

  9. Visual Studio Code 入门教程

    Extensible and customizable.(可扩展的和可定制的,这是我喜欢它的原因) Want even more features? Install extensions to add ...

  10. ansible使用5-Variables

    变量命名 支持数字.字母.下划线 有效:foo_port, foo5 无效:foo-port, foo port, foo.port, 12 playbook定义 - hosts: webserver ...