406317: GYM102354 I From Modular to Rational
Description
This is an interactive problem.
Someone picked a positive rational number $$$x=p/q$$$ where $$$1 \leq p, q \leq 10^9$$$. You may ask at most $$$10$$$ queries of the kind "? $$$m$$$", where $$$10^9 < m < 10^{12}$$$ and $$$m$$$ is a prime number. For each query, you will get the number $$$y$$$ such that $$$y \equiv pq^{-1} \pmod{m}$$$. You have to guess the number $$$x$$$.
InteractionThe first line of input contains a single integer $$$t$$$, the number of test cases ($$$1 \leq t \leq 10^5$$$).
For each test case, you may ask at most $$$10$$$ queries. Each query should be one of two types:
- "? $$$m$$$", where $$$10^9 < m < 10^{12}$$$ and $$$m$$$ is a prime number,
- "! $$$p$$$ $$$q$$$", where $$$1 \leq p, q \leq 10^9$$$, meaning that the answer is equal to $$$p/q$$$.
3 1 500000004 2Output
? 1000000007 ! 1 1 ? 1000000007 ! 2 4 ? 1000000007 ! 2 1Note
In the example, you deal with $$$x=1/1$$$, $$$x=1/2$$$, and $$$x=2/1$$$, while always taking $$$m=10^9+7$$$.
As you may see, it is not necessary to have $$$\gcd(p,q)=1$$$ as long as $$$1\leq p,q\leq 10^9$$$ and $$$x=p/q$$$.