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. AppCan试用体验

    最近自己想开发一个基于Android平台的小应用,但不想使用JAVA开发,还要快速实现功能,学习成本低. 所以找了很多框架,最后基本锁定在phoneGap和AppCan,又看了AppCan与phone ...

  2. hdu1576逆元的一道水题

    hdu 1576 Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1).   ...

  3. 用Margin还是用Padding?

    用margin还是用padding这个问题是每个学习CSS进阶时的必经之路. CSS边距属性定义元素周围的空间.通过使用单独的属性,可以对上.右.下.左的外边距进行设置.也可以使用简写的外边距属性同时 ...

  4. JAVA判断一个字符串里面有没有汉字

    private static boolean checkIfExistChineseCharacter(String s) { return !(s.length() == s.getBytes(). ...

  5. H-1-B签证简介

    H 1-B签证简介 H 1-B签证是美国雇主为外籍高级技术人员申请的一种工作签证,有效期为3年,可在到期后再延长6年.每年新的配额是6.5万人,另外还有2万个名额是留给在美国获得高级学位(硕士以上学位 ...

  6. webpack最佳入门实践系列(5)

    9.路径相关 原来我们打包的东西都存放到了dist目录下,并没有进行分类存储,乱成一团,这一节我们就要处理一下打包的路径,让打包后的目录看起来更加优雅 9.1.代码准备 我们先建立起这样一个目录结构 ...

  7. python常用20库

    python核心库和统计 简述 1. Requests.最着名的http库由kenneth reitz编写.这是每个python开发人员必备的. 2. Scrapy.如果您参与webscraping, ...

  8. SpringMVC+MyBatis+Shiro 配置文件详解

    1.web.xml文件的配置 <?xml version="1.0" encoding="UTF-8"?> <web-app version= ...

  9. 关于try-catch-finally return 的面试题

    public class Test { public static void main(String[] args) { System.out.println(test()); } static in ...

  10. request_mem_region 与 ioremap【转】

    转自:http://blog.csdn.net/alada007/article/details/7700125 如果从根本上说起的话应该从Intel的处理器芯片与其它的芯片的不同说起,与这两个函数相 ...