atcoder#TENKA12017F. ModularPowerEquation!!
ModularPowerEquation!!
Score : points
Problem Statement
Process the queries below.
- You are given two integers and . Determine whether there exists a positive integer not exceeding such that , and find one if it exists.
Constraints
Inputs
Input is given from Standard Input in the following format:
Q
A_1 M_1
:
A_Q M_Q
Outputs
In the -th line, print if there is no integer that satisfies the condition. Otherwise, print an integer not exceeding such that . If there are multiple solutions, any of them will be accepted.
4
2 4
3 8
9 6
10 7
4
11
9
2
It can be seen that the condition is satisfied: , , and .
3
177 168
2028 88772
123456789 987654321
7953
234831584
471523108231963269