#P5491. Modular Square Root Equation
Modular Square Root Equation
Modular Square Root Equation
Given integers (N) and an odd prime (p), solve the congruence:
[ x^2 \equiv N \pmod{p} ]
The input consists of multiple test cases. For each test case, if the equation has a solution, output all solutions in increasing order in one line (if there are two distinct solutions, they are separated by a space). If no solution exists, output No solution
. Note that when (N = 0), the only solution is 0.
inputFormat
The first line contains an integer (T) denoting the number of test cases. Each of the following (T) lines contains two integers (N) and (p), where (p) is an odd prime.
outputFormat
For each test case, if the congruence (x^2 \equiv N \pmod{p}) has a solution, print all solutions in increasing order on a new line. If there is no solution, print No solution
.
sample
4
1 7
2 7
3 7
0 3
1 6
3 4
No solution
0
</p>