|
||||||||||
fractionTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 735 Accepted Submission(s): 402 Problem Description Many problems require printing the probability of something. Moreover, it is common that if the answer is $\frac{a}{b}$, you should output $a \times b^{-1} \pmod{p}$ ($p$ is a prime number). In these problems, you cannot know the exact value of the probability. It's so confusing!!! Now, we want to reverse engineer the exact probability from such calculated output value $x$. We do so by guessing the probability is the one with the minimum $b$ such that $a \times b^{-1} = x \pmod{p}$. Now we invite you to solve this problem with us! You are given two positive integers $p$ and $x$, where $p$ is a prime number. Please find the smallest positive integer $b$ such that there exist some positive integer $a$ satisfying $a < b$ and $a \equiv bx \pmod{p}$. Input The first line contains an integer $T$ indicating there are $T$ tests. Each test consists of a single line containing two integers: $p, x$. * $1 \le T \le 2 \times 10^5$ * $3 \le p \le 10^{15}$ * $p$ is a prime * $1 < x < p$ Output For each test, output a line containing a string represents the fraction $\frac{a}{b}$ using the format "a/b" (without quotes). Sample Input
Sample Output
Source | ||||||||||
|