/** Poj1808.c * created on: 2011-10-12 * Author: bjfuwangzhu * // **> consider the same formula as X2 limit N (mod m), where M> 1, (m, n) = 1. *> If there is a solution to the same formula, n is called the quadratic residue of the Modulo M. If there is no solution to the same formula, n is called the quadratic non-residue of the Modulo M. *> If P is an odd prime number, the number of Quadratic Residue and quadratic non-residue of the modulo p is exactly "half to half ", *> The following table shows the quadratic surplus and non-surplus of several small prime numbers: *> P residual non-surplus> 3 1 2> 5 2, 3, 3> 7 *> 1, 2, 4, 5, 6> 11, 10> 13 *>,>, *> if n is the quadratic residue of the modulo p, then n ^ (p-1)/2) limit 1 (mod P ). If n is the quadratic non-residue of the modulo p, *> then n ^ (p-1)/2) decimal-1 (mod P ). */# Include <stdio. h> # define ll long longint modular_exp (int A, int B, int c) {ll res, temp; Res = 1% C, temp = A % C; while (B) {If (B & 1) {res = res * temp % C;} temp = temp * temp % C; B >>=1 ;} return (INT) RES ;} void solve (int A, int p) {A = (a % P + p) % P; If (modular_exp (A, (p-1)/2, P) = 1) {puts ("1"); return;} puts ("-1");} int main () {# ifndef online_judgefreopen ("data. in "," r ", stdin); # endifint T, I, A, P; scanf (" % d ", & T); for (I = 1; I <= T; I ++) {scanf ("% d", & A, & P); printf ("Scenario # % d: \ n ", i); solve (A, P); printf ("\ n");} return 0 ;}