Codeforces Round 846 (Div. 2)
D
Bit Guessing Game
Codeforces
1800
原题
← BE →
翻译中…

This is an interactive problem.

翻译中…

Kira has a hidden positive integer $n$, and Hayato needs to guess it.

翻译中…

Initially, Kira gives Hayato the value $\mathrm{cnt}$ — the number of unit bits in the binary notation of $n$. To guess $n$, Hayato can only do operations of one kind: choose an integer $x$ and subtract it from $n$. Note that after each operation, the number $n$ changes. Kira doesn't like bad requests, so if Hayato tries to subtract a number $x$ greater than $n$, he will lose to Kira. After each operation, Kira gives Hayato the updated value $\mathrm{cnt}$ — the number of unit bits in the binary notation of the updated value of $n$.

翻译中…

Kira doesn't have much patience, so Hayato must guess the original value of $n$ after no more than $30$ operations.

翻译中…

Since Hayato is in elementary school, he asks for your help. Write a program that guesses the number $n$. Kira is an honest person, so he chooses the initial number $n$ before all operations and does not change it afterward.

翻译中…

Input

翻译中…

The input data contains several test cases. The first line contains one integer $t$ ($1 \le t \le 500$) — the number of test cases. The description of the test cases follows.

翻译中…

The first line of each test case contains the number $\mathrm{cnt}$ — the initial number of unit bits in the binary notation $n$.

翻译中…

The hidden integer $n$ satisfies the following constraint: $1 \le n \le 10^9$.

翻译中…

Interaction

翻译中…

To guess $n$, you can perform the operation at most $30$ times. To do that, print a line with the following format: "- x" ($1 \le x \le 10^9$).

翻译中…

After this operation, the number $x$ is subtracted from $n$, and therefore $n$ is changed. If the number $x$ is greater than the current value of $n$, then the request is considered invalid.

翻译中…

After the operation read a line containing a single non-negative integer $\mathrm{cnt}$ — the number of unit bits in the binary notation of the current $n$ after the operation.

翻译中…

When you know the initial value of $n$, print one line in the following format: "! n" ($1 \le n \le 10^9$).

翻译中…

After that, move on to the next test case, or terminate the program if there are none.

翻译中…

If your program performs more than $30$ operations for one test case, subtracts a number $x$ greater than $n$, or makes an incorrect request, then response to the request will be -1, after receiving such response, your program must exit immediately to receive the Wrong Answer verdict. Otherwise, you can get any other verdict.

翻译中…

After printing a query or the answer, do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

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

Hacks

翻译中…

To make a hack, use the following format.

翻译中…

The first line should contain a single integer $t$ ($1 \leq t \leq 500$).

翻译中…

Each test case should contain one integer $n$ ($1 \leq n \leq 10^9$) on a separate line.

翻译中…

Note

翻译中…

For example, the number of unit bits in number $6$ is $2$, because binary notation of $6$ is $110$. For $13$ the number of unit bits is $3$, because $13_{10} = 1101_2$.

翻译中…

In the first test case, $n = 1$, so the input is the number $1$. After subtracting one from $n$, it becomes zero, so the number of unit bits in it is $0$.

翻译中…

In the third test case, $n = 3$, which in binary representation looks like $3_{10} = 11_2$, so the input is the number of ones, that is $2$. After subtracting $2$, $n = 1$, so the number of unit bits is now $1$. After subtracting one from $n$, it becomes equal to zero.

翻译中…

Note that the blank lines in the input and output examples are shown for clarity and are not present in the actual interaction.

翻译中…

样例

Input #1
3

1

0

1

1

0

2

1

0
Output #1
- 1

! 1

- 1

- 1

! 2

- 2

- 1

! 3
InputCopy OutputCopy
题目信息
题号
1780D
时间限制
1 s
内存限制
256 MB
标签
二分
位运算
构造
交互题

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