Codeforces 757 E Bash Plays with Functions
Discription
Bash got tired on his journey to become the greatest Pokemon master. So he decides to take a break and play with functions.
Bash defines a function f0(n), which denotes the number of ways of factoring n into two factors p and q such that gcd(p, q) = 1. In other words, f0(n) is the number of ordered pairs of positive integers (p, q) such that p·q = n and gcd(p, q) = 1.
But Bash felt that it was too easy to calculate this function. So he defined a series of functions, where fr + 1 is defined as:
Where (u, v) is any ordered pair of positive integers, they need not to be co-prime.
Now Bash wants to know the value of fr(n) for different r and n. Since the value could be huge, he would like to know the value modulo 109 + 7. Help him!
Input
The first line contains an integer q (1 ≤ q ≤ 106) — the number of values Bash wants to know.
Each of the next q lines contain two integers r and n (0 ≤ r ≤ 106, 1 ≤ n ≤ 106), which denote Bash wants to know the value fr(n).
Output
Print q integers. For each pair of r and n given, print fr(n) modulo 109 + 7 on a separate line.
Example
5
0 30
1 25
3 65
2 5
4 48
8
5
25
4
630 题解见代码注释。
就是个积性函数的题
/*
首先可以发现f0(x)=2^k ,其中k为x的质因子数。
然后对于r>=1, fr(x)=Σfr-1(d) 其中d|x。 又∵f0是积性函数,fr=fr-1卷1,所以fr也是积性函数。
所以fr(x)=πfr(pi^ai) 还可以发现的是只要ai一样的话fr(pi^ai)是一样的,
所以fr(pi^ai)只与质因子的次数有关。 */
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<algorithm>
#define ll long long
#define maxn 1000005
#define pb push_back
using namespace std;
const ll ha=1000000007;
struct req{
int num,ci;
};
vector<req> g[maxn];
int f[maxn][23],T,mx;
int R,N,ans[maxn]; inline int add(int x,int y){
x+=y;
if(x>=ha) return x-ha;
else return x;
} inline void dp(){
f[0][0]=1;
for(int i=1;i<=20;i++){
f[0][i]=2;
} for(int i=1;i<=mx;i++){
f[i][0]=f[i-1][0];
for(int j=1;j<=20;j++) f[i][j]=add(f[i][j-1],f[i-1][j]);
}
} bool v[maxn]; inline void init(){
fill(ans+1,ans+T+1,1);
int now,c,sz;
req x;
for(int i=2;i<=1000000;i++) if(!v[i]){
for(int j=i;j<=1000000;j+=i){
v[j]=1;
sz=g[j].size();
if(sz){
now=j,c=0;
while(!(now%i)) now/=i,c++;
for(int k=0;k<sz;k++){
x=g[j][k];
ans[x.num]=ans[x.num]*(ll)f[x.ci][c]%ha;
}
}
}
}
} int main(){
scanf("%d",&T);
for(int i=1;i<=T;i++){
scanf("%d%d",&R,&N);
mx=max(mx,R);
g[N].pb((req){i,R});
}
dp();
init(); for(int i=1;i<=T;i++) printf("%d\n",ans[i]);
return 0;
}
Codeforces 757 E Bash Plays with Functions的更多相关文章
- 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] ...
- [Codeforces 757E] Bash Plays with Functions (数论)
题目链接: http://codeforces.com/contest/757/problem/E?csrf_token=f6c272cce871728ac1c239c34006ae90 题目: 题解 ...
- Codeforces E. Bash Plays with Functions(积性函数DP)
链接 codeforces 题解 结论:\(f_0(n)=2^{n的质因子个数}\)= 根据性质可知\(f_0()\)是一个积性函数 对于\(f_{r+1}()\)化一下式子 对于 \[f_{r+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 ...
- codeforces757E. Bash Plays with Functions(狄利克雷卷积 积性函数)
http://codeforces.com/contest/757/problem/E 题意 Sol 非常骚的一道题 首先把给的式子化一下,设$u = d$,那么$v = n / d$ $$f_r(n ...
- CF 757E Bash Plays with Functions——积性函数+dp+质因数分解
题目:http://codeforces.com/contest/757/problem/E f0[n]=2^m,其中m是n的质因子个数(种类数).大概是一种质因数只能放在 d 或 n/d 两者之一. ...
- 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 ...
- CF757E Bash Plays with Functions
题解 q<=1e6,询问非常多.而n,r也很大,必须要预处理所有的答案,询问的时候,能比较快速地查询. 离线也是没有什么意义的,因为必须递推. 先翻译$f_0(n)$ $f_0(n)=\sum_ ...
随机推荐
- rabbitmq之rpc
环境:windows或者Linux,python3.6,rabbitmq3.5要求: 可以对指定机器异步的执行多个命令 例子: >>:run "df -h" --hos ...
- 【转载】Unity3D研究院之IOS自定义游戏摇杆与飞机平滑的移动
移动开发游戏中使用到的触摸游戏摇杆在iPhone上是非常普遍的,毕竟是全触摸屏手机,今天MOMO 通过一个小例子和大家讨论Unity3D 中如何自定义一个漂亮的全触摸游戏摇杆. 值得高兴 ...
- 【志银】#define lowbit(x) ((x)&(-x))原理详解
分析下列语句 #define lowbit(x) ((x)&(-x)) 可写成下列形式: int Lowbit(x) { return x&(-x); } 例1:x = 1 十进制转二 ...
- 史林枫:开源HtmlAgilityPack公共小类库封装 - 网页采集(爬虫)辅助解析利器【附源码+可视化工具推荐】
做开发的,可能都做过信息采集相关的程序,史林枫也经常做一些数据采集或某些网站的业务办理自动化操作软件. 获取目标网页的信息很简单,使用网络编程,利用HttpWebResponse.HttpWebReq ...
- margin百分比,重叠和auto
一. margin百分比 1. 普通元素的百分比margin都是相对于容器的宽度计算 2. 绝对定位元素的百分比margin是相对于第一个定位祖先元素(relative/absolute/fixed) ...
- font-family 定义的最后为什么要加一句sans-serif
定义font-family时,最好在最后加一个sans-serif,这样如果所列出的字体都不能用,则默认的sans-serif字体能保证调用; W3C建议字体定义的时候,最后以一个类别的字体结束,例如 ...
- Angular中checkbox实现复选
需求:实现点击子选项,父选项自动勾选,当子选项没有勾选,对应的父选项不勾选,并把勾选的对应的id发送出去. 效果图: <!DOCTYPE html> <html data-ng-ap ...
- div盒子模型(一图胜千言)
offsetLeft 获取的是相对于父对象的左边距 left 获取或设置相对于 具有定位属性(position定义为relative)的父对象 的左边距 如果父div的position定义为relat ...
- 汕头市队赛 SRM14 T2 最长上升子序列
最长上升子序列 (tree.pas/c/cpp) 128MB 1s 有一个长度为n的序列a[i],其中1到n的整数各自在a[i]中出现恰好一次. 现在已知另一个等长的序列f[i],表示a[i]中以第i ...
- [ CodeVS冲杯之路 ] P3116
不充钱,你怎么AC? 题目:http://codevs.cn/problem/3116/ 基础的高精度加法,注意一下两个数长短不一和答案第一位的处理即可,当然也可以用压位的方法做 #include&l ...