Codeforces Round 781 (Div. 2)
D
GCD Guess
Codeforces
2000
原题
← CE →
翻译中…

This is an interactive problem.

翻译中…

There is a positive integer $1 \le x \le 10^9$ that you have to guess.

翻译中…

In one query you can choose two positive integers $a \neq b$. As an answer to this query you will get $\gcd(x + a, x + b)$, where $\gcd(n, m)$ is the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest common divisor) of the numbers $n$ and $m$.

翻译中…

To guess one hidden number $x$ you are allowed to make no more than $30$ queries.

翻译中…

Input

翻译中…

The first line of input contains a single integer $t$ ($1 \le t \le 1000$) denoting the number of test cases.

翻译中…

The integer $x$ that you have to guess satisfies the constraints: ($1 \le x \le 10^9$).

翻译中…

Interaction

翻译中…

The hidden number $x$ is fixed before the start of the interaction and does not depend on your queries.

翻译中…

To guess each $x$ you can make no more than $30$ queries in the following way:

翻译中…
  • "? a b" ($1 \le a, b \le 2 \cdot 10^9$, $a \neq b$).
翻译中…

For this query you will get $\gcd(x + a, x + b)$.

翻译中…

When you know $x$, print a single line in the following format.

翻译中…
  • "! x" ($1 \le x \le 10^9$).
翻译中…

After that continue to solve the next test case.

翻译中…

If you ask more than $30$ queries for one $x$ or make an invalid query, the interactor will terminate immediately and your program will receive verdict Wrong Answer.

翻译中…

After printing each query do not forget to output end of line and flush the output buffer. Otherwise, you will get the Idleness limit exceeded verdict. To do flush use:

翻译中…
  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • Read documentation for other languages.
翻译中…

Hacks

翻译中…

To use hacks, use the following format of tests:

翻译中…

The first line should contain a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.

翻译中…

The first and only line of each test case should contain a single integer $x$ ($1 \le x \le 10^9$) denoting the integer $x$ that should be guessed.

翻译中…

Note

翻译中…

The first hidden number is $4$, that's why the answers for the queries are:

翻译中…

"? 1 2" — $\gcd(4 + 1, 4 + 2) = \gcd(5, 6) = 1$.

翻译中…

"? 12 4" — $\gcd(4 + 12, 4 + 4) = \gcd(16, 8) = 8$.

翻译中…

The second hidden number is $10^9$, that's why the answer for the query is:

翻译中…

"? 2000000000 1999999999" — $\gcd(3 \cdot 10^9, 3 \cdot 10^9 - 1) = 1$.

翻译中…

These queries are made only for understanding the interaction and are not enough for finding the true $x$.

翻译中…

样例

Input #1
2

1

8

1
Output #1
? 1 2

? 12 4

! 4
? 2000000000 1999999999

! 1000000000
InputCopy OutputCopy
题目信息
题号
1665D
时间限制
3 s
内存限制
256 MB
标签
位运算
中国剩余定理
构造
博弈论
交互题
数学
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。