There are two friends Ranbir and Alia. Ranbir gave a question to Alia that you are given βQβ queries in the form [N, P].
For each query, Alia has to count how many arrays consisting of positive integers of size βNβ she could build such that the product of all the array elements is equal to βPβ.
Since the answer could be large, return the answer to each query modulo 10^9 + 7.
The first line of input contains an integer βTβ, denoting the number of test cases.
The first line of each test contains an integer βQβ denoting the total number of Queries.
Then each of the next βQβ lines contains two space-separated integers βNβ and βPβ denoting the size of the array to be formed and the product it should have after the array is formed respectively.
Output format :
For each test case, print the count of arrays formed for each query in a single line.
Output for each test case is printed on a separate line.
Note :
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= Q <= 10^4
1 <= N , P <= 10^4
Time Limit: 1 sec
2
2
2 6
1 1
1
5 1
4 1
1
For the first test case, consider each query independently
For the first query where we have to build an array of size 2 and the product of array, elements should be equal to 6. So all the possible arrays are: {1, 6}, {6, 1}, {2, 3} and {3, 2}. Therefore, the answer will be 4 for the given query.
For the second query where we have to build an array of size 1 and the product of the array, elements should be equal to 1. So the only possible array is {1}. Therefore, the answer will be 1 for the given query.
For the second test case, consider each query independently
For the first query where we have to build an array of size 5 and the product of array elements should be equal to 1. So the only possible array is {1, 1, 1, 1, 1}. Therefore, the answer will be 1 for the given query.
2
2
7 20
2 2
2
3 6
3 4
196 2
9 6
Make a dynamic programming solution where each DP[i][j] state will denote ways to fill i places in an array whose product is j.
DP[i][j] = DP[i][j] + sum of (DP[i-1][j / divisors(j)]).
Algorithm:
O(Q * N * P * Sqrt(P)), where βQβ is the total number of queries, βNβ is the size of the array to build and βPβ is the product that the array should have.
Since we are iterating over all queries which take O(Q) time and for each query we are constructing a DP table of size (N+1) * (P+1) and for each value of P, we are calculating its divisors which in total take O(N * P * Sqrt(P)) time.
So overall time complexity will be O(Q * N * P * Sqrt(P)).
O(N * P), where βNβ is the size of the array to build and βPβ is the product that the array should have.
Since we are constructing a DP table of size (N+1) * (P+1) which takes O(N * P) space. So overall space complexity will be O(N * P).