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. 牛客网Java刷题知识点之代码块(局部代码快、构造代码块、静态代码块)

    不多说,直接上干货! 代码块包括局部代码快.构造代码块.静态代码块. 代码块,就是一段独立的代码空间. 1.局部代码快 对局部变量的生命周期进行控制. 2.构造代码块 对所有对象进行初始化. 3.静态 ...

  2. pat1043. Is It a Binary Search Tree (25)

    1043. Is It a Binary Search Tree (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...

  3. Java学习第十六天

    1:List的子类(掌握) (1)List的子类特点 ArrayList: 底层数据结构是数组,查询快,增删慢 线程不安全,效率高 Vector: 底层数据结构是数组,查询快,增删慢 线程安全,效率低 ...

  4. System.Net.Mail

    System.Net.Mail命名空间包含用于将电子邮件发送到简单邮件传输协议(SMTP)服务器进行传送的类. 在此命名空间中,有两个很重要的类:  MailMessage 表示可以使用SmtpCli ...

  5. Spring-cloud微服务 Eureka学习教程-分布式搭建EurekaServer、EurekaClient(中级)

    我们这里只有一台服务器,所以我们先仿集群搭建. 完整demo项目代码:https://github.com/wades2/EurekaDemo2 在这之前我们先分析分析Eureka相比其他注册中心的好 ...

  6. IDEA检出SVN项目

    https://blog.csdn.net/qq_27093465/article/details/74898489 https://jingyan.baidu.com/article/47a29f2 ...

  7. oracle笔记1:-安装-体系结构-基本查询

    一.Oracle数据库的安装(安装在虚拟机的xp系统里)     1.安装虚拟机     2.虚拟机内安装xp系统,以下步骤在虚拟机内进行     3.双击setup.exe,在出现的界面中设置口令, ...

  8. C++ Knowledge series Template & Class

    Function Function is composed of name, parameter (operand, type of operand), return value, body with ...

  9. Appium 滑动界面swipe用法

    Appium 滑动API:Swipe(int start x,int start y,int end x,int y,duration) 解释:int start x-开始滑动的x坐标, int st ...

  10. Java -GUI开发九九乘法表

    Java GUI开发九九乘法表 (1)实现目标: 利用java自带的awt包,基础控件开发一个九九乘法表,点击可以显示对应的乘法口诀. (2)控件选择: 点击——Button 显示——TextFiel ...