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

Input
5
0 30
1 25
3 65
2 5
4 48
Output
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的更多相关文章

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

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

  2. 【codeforces 757E】Bash Plays with Functions

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

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

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

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

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

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

  6. codeforces757E. Bash Plays with Functions(狄利克雷卷积 积性函数)

    http://codeforces.com/contest/757/problem/E 题意 Sol 非常骚的一道题 首先把给的式子化一下,设$u = d$,那么$v = n / d$ $$f_r(n ...

  7. CF 757E Bash Plays with Functions——积性函数+dp+质因数分解

    题目:http://codeforces.com/contest/757/problem/E f0[n]=2^m,其中m是n的质因子个数(种类数).大概是一种质因数只能放在 d 或 n/d 两者之一. ...

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

  9. CF757E Bash Plays with Functions

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

随机推荐

  1. Metadata 的概念

    https://www.ibm.com/developerworks/cn/cloud/library/1509_liukg_openstackmeta/ http://mathslinux.org/ ...

  2. OZ常见错误解决办法

    执行成功 错误信息解决办法 libvirt.libvirtError: Failed to connect socket to '/var/run/libvirt/libvirt-sock': No ...

  3. 使用UltraEdit搭建自己的C/C++ IDE

    使用UltraEdit搭建自己的C/C++ IDE CodeBlocks的13.12版本啊,主要缺点是启动慢,而且在Windows上容易假死,写着写着就无响应了,然后死活活不过来.所以没办法,只好干脆 ...

  4. FOJ Problem 1015 土地划分

    Problem 1015 土地划分 Accept: 823    Submit: 1956Time Limit: 1000 mSec    Memory Limit : 32768 KB  Probl ...

  5. linux下的静态库和共享库

    转载&&增加:      我们在编写一个C语言程序的时候,经常会遇到好多重复或常用的部分,如果每次都重新编写固然是可以的,不过那样会大大降低工作效率,并且影响代码的可读性,更不利于后期 ...

  6. [blockchain-035]eos的部署安装智能合约

    0.参考资料 https://github.com/EOSIO/eos/wiki 1. eos的github地址 https://github.com/EOSIO/eos 2.下载eos源码 git ...

  7. BZOJ 1208 [HNOI2004]宠物收养所 | SPlay模板题

    题目: 洛谷也能评 题解: 记录一下当前树维护是宠物还是人,用Splay维护插入和删除. 对于任何一次询问操作都求一下value的前驱和后继(这里前驱和后继是可以和value相等的),比较哪个差值绝对 ...

  8. BZOJ2157 旅游 【树剖 或 LCT】

    题目 Ray 乐忠于旅游,这次他来到了T 城.T 城是一个水上城市,一共有 N 个景点,有些景点之间会用一座桥连接.为了方便游客到达每个景点但又为了节约成本,T 城的任意两个景点之间有且只有一条路径. ...

  9. [解决方案]IIS7.5 报错:无法启动计算机“."上的服务W3SVC

    报错场景: 在云服务器上,正常使用着,突然今天一打开网站就都用不了了,上去服务器一看,IIS中站点被停止了,我还怀疑是回收的问题,结果一直启动无果,我打算重启来解决这个问题,重启后发现所有站点都变成停 ...

  10. (poj)Sequence Median

    Description Given a sequence of N nonnegative integers. Let's define the median of such sequence. If ...