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. Python调用Webservice

    使用Python调用webservice 推荐使用 suds包 该包一般在Python2.x   python3各种麻烦 略过 实例 import suds # webservice url url ...

  2. Rbac_权限管理

    click!!! https://github.com/ugfly1210/rbac_100 有关于 rbac 的所有代码,包括 README. 用户和角色 : 多对多字段放在哪张表更好点? 用户找角 ...

  3. C#向上转型与向下转型(转)

    原文地址:https://blog.csdn.net/wangqingbo0829/article/details/48474173 向上转型:将子类对象转为父类对象.此处父类对象可以是接口. 向下转 ...

  4. sql 游标使用

    declare @PASSDate datetime,@VLPN varchar(50),@VLPNColor varchar(10),@nambers int set @VLPN='';set @V ...

  5. URAL 1684. Jack's Last Word ( KMP next函数应用 )

    题意:问第二行的串能不能恰好分割成几个串,使得这几个串都是第一行串的前缀.如果是,输出No, 并输出这几个串,否则输出Yes. 这题是Special Judge,把两个串连接起来,中间用一个未出现过的 ...

  6. 团队项目-第八次scrum 会议

    时间:11.4 时长:30分钟 地点:F楼2层沙发休息处 工作情况 团队成员 已完成任务 待完成任务 解小锐 修复员工招聘时bug 完成员工commit函数的数值函数编写 陈鑫 实现雇佣与解雇功能的界 ...

  7. 用Linkedhashmap的LRU特性及SoftReference软引用构建二级缓存

    LRU: least recently used(近期最少使用算法).LinkedHashMap构造函数可以指定其迭代顺序:LinkedHashMap(int initialCapacity, flo ...

  8. 软件工程概论课堂测试一————添加新课程(web)

    设计思想 三个文件Class_add.java  add.jsp  addInput.jsp Class_add.java : 内封装方法:连接数据库.向数据库添加课程信息.判断非合理的输入情况.判断 ...

  9. sqlachemy 原生sql输出

    在创建引擎时,将echo参数配置成True,会输出sql执行语句记录.默认False create_engine(statsticConf.sqlalchemy_mysql,connect_args= ...

  10. 【bzoj1511】[POI2006]OKR-Periods of Words KMP-next数组

    原文地址:http://www.cnblogs.com/GXZlegend/p/6827027.html 题目描述 一个串是有限个小写字符的序列,特别的,一个空序列也可以是一个串. 一个串P是串A的前 ...