#P61. [KBC005E] Count 2
[KBC005E] Count 2
Source
This problem is adapted from Long Long OJ, and the copyright belongs to Codeforces.
Problem Source: https://codeforces.com/contest/893/problem/E
Problem Description
There are multiple test cases. For each test case, given and , find the number of sequences of length whose product equals .
Negative numbers are allowed in the sequence. Calculate the number of such sequences, modulo .
Input Format
This problem contains multiple test cases.
The first line contains an integer () — the number of test cases to solve.
The next lines each contain two integers and (). Each line represents a test case.
Output Format
Output integers. The -th integer should be the number of sequences modulo .
Samples
2
6 3
4 2
36
6
Sample Explanation
The possible sequences are as follows:
- ;
- ;
- ;
- ;
- ;
- .