310027: CF1773I. Interactive Factorial Guessing

Memory Limit:1024 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Interactive Factorial Guessing

题意翻译

- **这是一道交互题。** - 交互库有一个整数 $n\in[1,5982]$,你可以询问 $n!$ 的第 $x$ 位不超过 $10$ 次,猜出这个 $n$。 - 注:你必须唯一确定 $n$。

题目描述

Oh no, this wicked jury hides something from you again, and you need to guess it interactively. This time, you need to find an integer $ n $ . To do that, you can make at most 10 queries of the form "What is the $ k $ -th decimal digit of the product of all integers from 1 to $ n $ (also known as factorial and denoted as $ n! $ )?".

输入输出格式

输入格式


输出格式


In the first line, there is an integer $ t $ ( $ 1 \le t \le 100 $ ) — the number of tests you shall process. For each test, the integer $ n $ is chosen in advance. The length of $ n! $ is at most $ 20\,000 $ , so $ 1 \le n \le 5982 $ . You can make at most 10 queries of the form "? $ k $ " ( $ 0 \le k < 20\,000 $ ). In response to the query, you will get a single digit — the $ k $ -th decimal digit of $ n! $ (the response is between 0 and 9 inclusive). Digits are numbered from 0, starting with the least significant digit. If $ n! $ is too short, and there is no $ k $ -th digit, then 0 is returned. After your program finds the value of $ n $ it shall answer with "! $ n $ ". If the answer is correct, then you will receive "YES" and should proceed to the next test or terminate if it was the last one. If the answer is not correct, or you are trying to guess, and there are several possible answers consistent with the information you have received, you will get "NO". In that case, your submission will receive "Wrong answer" verdict and your code shall terminate immediately.

输入输出样例

输入样例 #1

2

1

YES

0

2

YES

输出样例 #1

? 0

! 1

? 0

? 19997

! 5982

Input

题意翻译

- **这是一道交互题。** - 交互库有一个整数 $n\in[1,5982]$,你可以询问 $n!$ 的第 $x$ 位不超过 $10$ 次,猜出这个 $n$。 - 注:你必须唯一确定 $n$。

Output

**题意翻译**

- **这是一道交互题。**
- 交互库有一个整数 \( n \in [1,5982] \),你可以询问 \( n! \) 的第 \( x \) 位不超过 10 次,猜出这个 \( n \)。
- 注:你必须唯一确定 \( n \)。

**题目描述**

哦不,这个邪恶的陪审团又再次对你隐瞒了一些事情,你需要通过交互式的方式来猜测它。

这一次,你需要找到一个整数 \( n \)。为了做到这一点,你可以最多进行 10 次形式为 " \( n! \)(也就是从 1 到 \( n \) 的所有整数的乘积,也被称为阶乘)的第 \( k \) 位小数是多少?" 的查询。

**输入输出格式**

**输入格式**

\( t \)(\( 1 \le t \le 100 \))—— 你将处理的测试数量。

对于每个测试,整数 \( n \) 是预先选定的。\( n! \) 的长度最多为 \( 20,000 \),所以 \( 1 \le n \le 5982 \)。

你可以最多进行 10 次形式为 "? \( k \)"(\( 0 \le k < 20,000 \))的查询。作为对查询的响应,你将得到一个单一的数字 —— \( n! \) 的第 \( k \) 位小数(响应在 0 到 9 之间,包括 0 和 9)。数字从 0 开始编号,从最低有效位开始。如果 \( n! \) 过短,并且没有第 \( k \) 位数字,那么返回 0。

当你的程序找到 \( n \) 的值时,它应以 "! \( n \)" 的形式回答。如果答案正确,那么你将收到 "YES",并应继续进行下一个测试,或者如果它是最后一个测试就终止。如果答案不正确,或者你试图猜测,并且根据你收到的信息有多个可能的答案,你将得到 "NO"。在这种情况下,你的提交将收到 "Wrong answer" 判决,并且你的代码应立即终止。

**输入输出样例**

**输入样例 #1**

```
2
1
YES
0
2
YES
```

**输出样例 #1**

```
? 0
! 1
? 0
? 19997
! 5982
```**题意翻译** - **这是一道交互题。** - 交互库有一个整数 \( n \in [1,5982] \),你可以询问 \( n! \) 的第 \( x \) 位不超过 10 次,猜出这个 \( n \)。 - 注:你必须唯一确定 \( n \)。 **题目描述** 哦不,这个邪恶的陪审团又再次对你隐瞒了一些事情,你需要通过交互式的方式来猜测它。 这一次,你需要找到一个整数 \( n \)。为了做到这一点,你可以最多进行 10 次形式为 " \( n! \)(也就是从 1 到 \( n \) 的所有整数的乘积,也被称为阶乘)的第 \( k \) 位小数是多少?" 的查询。 **输入输出格式** **输入格式** \( t \)(\( 1 \le t \le 100 \))—— 你将处理的测试数量。 对于每个测试,整数 \( n \) 是预先选定的。\( n! \) 的长度最多为 \( 20,000 \),所以 \( 1 \le n \le 5982 \)。 你可以最多进行 10 次形式为 "? \( k \)"(\( 0 \le k < 20,000 \))的查询。作为对查询的响应,你将得到一个单一的数字 —— \( n! \) 的第 \( k \) 位小数(响应在 0 到 9 之间,包括 0 和 9)。数字从 0 开始编号,从最低有效位开始。如果 \( n! \) 过短,并且没有第 \( k \) 位数字,那么返回 0。 当你的程序找到 \( n \) 的值时,它应以 "! \( n \)" 的形式回答。如果答案正确,那么你将收到 "YES",并应继续进行下一个测试,或者如果它是最后一个测试就终止。如果答案不正确,或者你试图猜测,并且根据你收到的信息有多个可能的答案,你将得到 "NO"。在这种情况下,你的提交将收到 "Wrong answer" 判决,并且你的代码应立即终止。 **输入输出样例** **输入样例 #1** ``` 2 1 YES 0 2 YES ``` **输出样例 #1** ``` ? 0 ! 1 ? 0 ? 19997 ! 5982 ```

加入题单

算法标签: