#P16457. [UOI 2026] Guess the Number

    ID: 16443 Type: RemoteJudge 1000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>二分交互题Special Judge2026UOI(乌克兰)

[UOI 2026] Guess the Number

题目描述

An integer nn is hidden (1n<1081 \le n < 10^8), and it is not divisible by 1010. Your task is to find this number.

You may ask queries of the following form: choose an integer xx (1x1091 \le x \le 10^9). In response, you will receive the first digit of the number nxn \cdot x.

The first digit of a positive integer is its most significant digit in decimal notation. For example, the first digit of the numbers 77, 4242, 123456123456 is respectively 77, 44, 11.

You need to find the hidden number nn. You can use at most 2828 queries for each testcase.

输入格式

The first line contains two integers tt and qq (1t103,q=281 \le t \le 10^3, q=28) --- the number of testcases and the maximum number of queries that can be used in each testcase.

Interaction

In each testcase, a separate number nn is hidden.

To make a query, print $$\texttt{? } x$$, where 1x1091 \le x \le 10^9.

In response to a query, the jury program will print one integer dd (1d91 \le d \le 9) --- the first digit of the number nxn \cdot x.

After printing a query, do not forget to print a newline and flush the output buffer. Otherwise, you will receive the verdict Timelimitexceeded\tt{Time limit exceeded}. To flush the buffer, use:

  • fflush(stdout)\tt{fflush(stdout)} or cout.flush()\tt{cout.flush()} in C++;
  • System.out.flush()\tt{System.out.flush()} in Java;
  • flush(output)\tt{flush(output)} in Pascal;
  • stdout.flush()\tt{stdout.flush()} in Python.

When you have determined the hidden number nn, print $$\texttt{! } n$$.

After that, if this was the last testcase, you must terminate your program. Otherwise, you should continue the interaction with the next testcase.

qq is the maximum number of ?\texttt{?} queries that your program may use in one testcase. Printing an answer of the form !\texttt{!} does not count as a query.

Note that if your query is invalid, the interactor will print -1\texttt{-1} and terminate. A query is considered invalid if:

  • xx does not satisfy the constraint 1x1091 \le x \le 10^9;
  • the number of queries in the current testcase exceeded qq;
  • the answer ! n\texttt{! } n is incorrect.

If you read -1\texttt{-1}, immediately terminate your program to receive the verdict Wronganswer\tt{Wrong answer} instead of an arbitrary verdict.

1 28
1
6
? 1
? 59
! 11

提示

Consider the example. Suppose that in this example it is additionally known that the hidden number is less than 100100.

After the query x=1x = 1 and the answer 11, we understand that the first digit of the hidden number is 11.

After the query x=59x = 59 and the answer 66, we understand that the first digit of the product of the hidden number and 5959 is 66.

Among all numbers less than 100100 that are not divisible by 1010, only the number 1111 satisfies both conditions. Therefore, the answer in the example is 1111.

Scoring

  • (22 points): n10n \le 10;
  • (66 points): n100n \le 100;
  • (77 points): n1000n \le 1000;
  • (88 points): n10000n \le 10000;
  • (1010 points): nn is a perfect square;
  • (1010 points): n105n \le 10^5;
  • (1111 points): n106n \le 10^6;
  • (1212 points): n107n \le 10^7;
  • (1414 points): n5107n \le 5 \cdot 10^7;
  • (2020 points): no additional constraints.

A solution passes a subtask only if it correctly finds the number nn for every testcase of that subtask, using no more than qq queries in each one.