#Lutece0447. T-Residual Set
T-Residual Set
Migrated from Lutece 447 T-Residual Set
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
Given a pair of number where is a prime and is a non-negative integer.
The Residual Set
of any prime number is all the integers between and ,
that is, .
What's more, a T-Residual Set
of any prime number p means the set of integers below:
$1^T\ mod\ p, 2^T\ mod\ p, 3^T\ mod\ p, 4^T\ mod\ p, \cdots (p-2)^T\ mod \ p, (p-1)^T\ mod \ p$, where must be non-negative.
Now for each pair of , you should calculate how many distinct numbers there are in the t-Residual Set
of .
Input
A number () in first line.
Then test cases follow.
Each Test case contains two number () and (),
which meanings areaccording to the description.
Output
Output lines.
Each line contains one number, refers to the answer.
Samples
3
7 9
17 89
47 56
2
16
23
Resources
5th BUPT Programming Contest Final