F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

fraction

Time 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
3 11 7 998244353 554580197 998244353 998244352
 

Sample Output
2/5 8/9 499122176/499122177
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-26 02:13:52, Gzip enabled