Problem A. fraction

时间限制 1000 ms   内存限制 256 MB

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}$.
 

输入数据

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$
 

输出数据

For each test, output a line containing a string represents the fraction $\frac{a}{b}$ using the format "a/b" (without quotes).
 

样例输入

复制
3
11 7
998244353 554580197
998244353 998244352

样例输出

复制
2/5
8/9
499122176/499122177

提交

请先 登录

© 2025 FAQs Contact About