#P16457. [UOI 2026] Guess the Number
[UOI 2026] Guess the Number
题目描述
An integer is hidden (), and it is not divisible by . Your task is to find this number.
You may ask queries of the following form: choose an integer (). In response, you will receive the first digit of the number .
The first digit of a positive integer is its most significant digit in decimal notation. For example, the first digit of the numbers , , is respectively , , .
You need to find the hidden number . You can use at most queries for each testcase.
输入格式
The first line contains two integers and () --- the number of testcases and the maximum number of queries that can be used in each testcase.
Interaction
In each testcase, a separate number is hidden.
To make a query, print $$\texttt{? } x$$, where .
In response to a query, the jury program will print one integer () --- the first digit of the number .
After printing a query, do not forget to print a newline and flush the output buffer. Otherwise, you will receive the verdict . To flush the buffer, use:
- or in C++;
- in Java;
- in Pascal;
- in Python.
When you have determined the hidden number , 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.
is the maximum number of queries that your program may use in one testcase. Printing an answer of the form does not count as a query.
Note that if your query is invalid, the interactor will print and terminate. A query is considered invalid if:
- does not satisfy the constraint ;
- the number of queries in the current testcase exceeded ;
- the answer is incorrect.
If you read , immediately terminate your program to receive the verdict 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 .
After the query and the answer , we understand that the first digit of the hidden number is .
After the query and the answer , we understand that the first digit of the product of the hidden number and is .
Among all numbers less than that are not divisible by , only the number satisfies both conditions. Therefore, the answer in the example is .
Scoring
- ( points): ;
- ( points): ;
- ( points): ;
- ( points): ;
- ( points): is a perfect square;
- ( points): ;
- ( points): ;
- ( points): ;
- ( points): ;
- ( points): no additional constraints.
A solution passes a subtask only if it correctly finds the number for every testcase of that subtask, using no more than queries in each one.