TopCoder

User's AC Ratio

100.0% (1/1)

Submission's AC Ratio

100.0% (2/2)

Tags

Description

Each test cases consists of $T$ cases.

Given $Y, P(P: \textrm{prime})$.

Print $X$ s.t. $X^ 2 \equiv Y (\bmod P)$, or $-1$ if there is no such $X$.

Input Format

$T$
$Y_ 0$ $P_ 0$
$Y_ 1$ $P_ 1$
:
$Y_ {T-1}$ $P_ {T-1}$

Output Format

For each line, print $X$ or $-1$.

Sample Input 1

5
0 5
1 5
2 5
3 5
4 5

Sample Output 1

0
1
-1
-1
2

Hints

  • $1 \leq T \leq 100,000$
  • $2 \leq P \leq 10^ 9$
  • $0 \leq Y < P$
  • $P$ is prime.

Problem Source

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 10000 2097152 2097152
1 10000 2097152 2097152
2 10000 2097152 2097152
3 10000 2097152 2097152
4 10000 2097152 2097152
5 10000 2097152 2097152
6 10000 2097152 2097152
7 10000 2097152 2097152
8 10000 2097152 2097152
9 10000 2097152 2097152
10 10000 2097152 2097152
11 10000 2097152 2097152
12 10000 2097152 2097152