#P11145. 「SFMOI Round I」Strange Homura Game

    ID: 10443 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>洛谷原创交互题Special JudgeO2优化洛谷月赛Ad-hoc

「SFMOI Round I」Strange Homura Game

Description

This problem is differ from B1. You had better read both statements.

This is an interactive problem.

Hint: We provide a formalized description of this problem at the end of the statement.

Homura and Madoka are playing a game.

Homura has thought of a positive integer mm, and Madoka need to determine its value.. It is guaranteed that 2m1017\textcolor{red}{2}\le m\le 10^{17}. Also, Homura doesn't cheat, that is, Madoka wouldn't change the value of mm during the whole game.

Madoka can ask Homura: for a non-negative integer xx, what is the value of xmodmx\bmod m. Madoka aimed to determine the value of mm with the number of queries as small as possible. (In order to get full points, you need to solve this problem within 22 queries.)

The game will be played for TT rounds. However, Madoka is at the military training, so she turned to you.

Formally, there exists a hidden positive integer m[2,1017]m\in [\textcolor{red}{2},10^{17}]. In each query, a non-negative integer xx is given, and it returns xmodmx \bmod m.

Find mm with the least number of queries. There are TT test cases.

The value of mm is read from input file and won't change according to queries. That is, the interactor is non-adaptive.

Implementation Details

Input a positive integer TT first, which stands for the number of the rounds.

For each test case:

  • Output a single line containing ? x\texttt{? }x to make a query. Then, an integer indicating xmodmx\bmod m is available.

    xx is a positive integer should be guaranteed, and xx must fall in [0,1018] \textcolor{red} {[0,10^{18}]}.

    If x=1x=-1 instead of the answer, it means that the query limit is excceeded, or the query is invalid. The solution should quit immediately.

  • Output a single line containing ! m\texttt{! }m to respond to the guess.

After outputting the queries, do not forget to output a newline character and flush the output buffer. Otherwise, you will receive the verdict TLE. To flush the buffer, use:

  • fflush(stdout) or cout.flush() in C++;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • refer to the documentation for other languages.

Input Format

See [Implementation Details].

Output Format

See [Implementation Details].

1

0

1

? 5

? 1

! 5

Hint

Constraints

It is guaranteed that

  • 1T1001\le T\le 100;
  • mm is a positive ineteger, and 2m1017\textcolor{red}{2}\le m\le 10^{17}

Scoring

Let QQ be the maximum queries used in each test. The score\mathrm{score} is calculated as following:

$$\begin{aligned} \mathrm{score}=\begin{cases} 0, & Q\in [101,+\infty) \\ 30, & Q\in [3,101) \\ 50, & Q\in [0,3) \\ \end{cases} \end{aligned}$$

The score of the task is the minimum score of each test.