#879. SWW and Functions
SWW and Functions
Background
SWW is a master of Number Theory. One day, she thought of a problem in her dream and she wants to challenge you.
She defines function f(n) as the number of different pairs that satisfies and .
It’s simple to calculate for any given , so she defines another function , where
Now, SWW wants you to calculate the value of , where
$$F_k(n) = \begin{cases} n & , k = 0 \\ f(F_{k - 1}(n)) & , k > 0, k≡1(mod\;2) \\ g(F_{k - 1}(n)) & , k > 0, k≡0(mod\;2) \end{cases} $$Input
There are multiple test cases.
The first line contains an integer , representing the number of test cases.
Each of the following T lines contains two integers and , where , .
Output
For each test case, you need to output one integer in a single line, which represents mod .
Samples
3
15 2
233 3
23333333333 3
8
112
271986803