CF2109C2.Hacking Numbers (Medium Version)

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is the medium version of the problem. In this version, you can send at most 4\mathbf{4} commands. You can make hacks only if all versions of the problem are solved.

This is an interactive problem.

Welcome, Duelists! In this interactive challenge, there is an unknown integer xx (1≤x≤1091 \le x \le 10^9). You must make it equal to a given integer in the input nn. By harnessing the power of "Mathmech" monsters, you can send a command to do one of the following:

Command

Constraint

Result

Case

Update

Jury's response

"add yy"

−1018≤y≤1018-10^{18} \le y \le 10^{18}

res=x+y\mathrm{res} = x + y

if 1≤res≤1018\text{if } 1 \le \mathrm{res} \le 10^{18}

x←resx \leftarrow \mathrm{res}

"1"

else\mathrm{else}

x←xx \leftarrow x

"0"

"mul yy"

1≤y≤10181 \le y \le 10^{18}

res=x⋅y\mathrm{res} = x \cdot y

if 1≤res≤1018\text{if } 1 \le \mathrm{res} \le 10^{18}

x←resx \leftarrow \mathrm{res}

"1"

else\mathrm{else}

x←xx \leftarrow x

"0"

"div yy"

1≤y≤10181 \le y \le 10^{18}

res=x/y\mathrm{res} = x/y

if y\text{if } y divides xx

x←resx \leftarrow \mathrm{res}

"1"

else\mathrm{else}

x←xx \leftarrow x

"0"

"digit"

—

res=S(x)\mathrm{res} = S(x)∗^{\text{∗}}

—

x←resx \leftarrow \mathrm{res}

"1"

You have to make xx equal to nn using at most 4\mathbf{4} commands.

∗^{\text{∗}}S(n)S(n) is a function that returns the sum of all the individual digits of a non-negative integer nn. For example, S(123)=1+2+3=6S(123) = 1 + 2 + 3 = 6

这是该题目的中等难度版本。在此版本中,你最多可以发送 4\mathbf{4} 条指令。仅当该题所有难度版本均已被解决时,你才可进行 Hack。

这是一道交互式问题。

欢迎各位决斗者!在此交互式挑战中,存在一个未知整数 xx(满足 1≤x≤1091 \le x \le 10^9)。你需要通过操作使其等于输入中给定的整数 nn。借助“数学机械”(Mathmech)怪兽的力量,你可以发送以下四种指令之一:

指令 约束条件 结果 情况 更新 评测机响应
"add $y$" −1018≤y≤1018-10^{18} \le y \le 10^{18} res=x+y\mathrm{res} = x + y 若 1≤res≤10181 \le \mathrm{res} \le 10^{18} x←resx \leftarrow \mathrm{res} "1"
否则 x←xx \leftarrow x "0"
"mul $y$" 1≤y≤10181 \le y \le 10^{18} res=x⋅y\mathrm{res} = x \cdot y 若 1≤res≤10181 \le \mathrm{res} \le 10^{18} x←resx \leftarrow \mathrm{res} "1"
否则 x←xx \leftarrow x "0"
"div $y$" 1≤y≤10181 \le y \le 10^{18} res=x/y\mathrm{res} = x/y 若 yy 整除 xx x←resx \leftarrow \mathrm{res} "1"
否则 x←xx \leftarrow x "0"
"digit" — res=S(x)\mathrm{res} = S(x)∗^{\text{∗}} — x←resx \leftarrow \mathrm{res} "1"

你必须在最多 4\mathbf{4} 条指令内使 xx 等于 nn。

∗^{\text{∗}} S(n)S(n) 是一个函数,返回非负整数 nn 的各位数字之和。例如,S(123)=1+2+3=6S(123) = 1 + 2 + 3 = 6。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤50001 \le t \le 5000). The description of the test cases follows.

The first and only line of each test case contains one integer nn (1≤n≤1091 \le n \le 10^9).

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤50001 \le t \le 5000)。随后是各测试用例的描述。

每个测试用例仅有一行,包含一个整数 nn(1≤n≤1091 \le n \le 10^9)。

输入输出样例

  • 输入#1

    2
    100
    
    0
    
    1
    
    1
    
    1
    
    5
    
    1
    
    1
    
    1

    输出#1

    add -10
    
    add 1
    
    mul 10
    
    !
    
    digit
    
    div 2
    
    !

说明/提示

Solution

Jury

Explanation

2\texttt{2}

There are 2 test cases.

100\texttt{100}

In the first test case, the unknown integer x=9x = 9 and we have to make it equal to n=100n = 100.

add -10\texttt{add -10}

0\texttt{0}

The answer to "add -10" is "0". This means that the addition command was not successful as x+y=9+(−10)≤0x + y = 9 + (-10) \le 0, and xx remains 99 after the command

add 1\texttt{add 1}

1\texttt{1}

The answer to "add 1" is "1". This means that the addition command was successful as x+y=9+1=10x + y = 9 + 1 = 10, and xx changes to 1010 after the command.

mul 10\texttt{mul 10}

1\texttt{1}

The answer to "mul 10" is "1". This means that the multiplication command was successful as x⋅y=10⋅10=100x \cdot y = 10 \cdot 10 = 100, and xx changes to 100100 after the command.

!\texttt{!}

1\texttt{1}

The answer to "!" is "1". This means you have determined that xx equals nn.

5\texttt{5}

In the second test case, the unknown integer x=1234x = 1234 and we have to make it equal to n=5n = 5.

digit\texttt{digit}

1\texttt{1}

The answer to "digit" is "1". This means that xx turned into the sum of its digits 1+2+3+4=101 + 2 + 3 + 4 = 10, and xx changes to 1010 after the command.

div 2\texttt{div 2}

1\texttt{1}

The answer to "div 2" is "1". This means that the division command was successful as y=2y = 2 is a divisor of x=10x = 10, and xx changes to xy=102=5\frac{x}{y} = \frac{10}{2} = 5 after the command.

!\texttt{!}

1\texttt{1}

The answer to "!" is "1". This means you have determined that xx equals nn.

Note that the empty lines in the example input and output are for the sake of clarity, and do not occur in the real interaction.

解答

裁判组

解释

2\texttt{2}

共有 2 个测试用例。

100\texttt{100}

在第一个测试用例中,未知整数 x=9x = 9,我们需要使其等于 n=100n = 100。

add -10\texttt{add -10}

0\texttt{0}

对命令 “add -10” 的响应是 “0”。这表示加法操作失败,因为 x+y=9+(−10)≤0x + y = 9 + (-10) \le 0,执行该命令后 xx 仍为 99。

add 1\texttt{add 1}

1\texttt{1}

对命令 “add 1” 的响应是 “1”。这表示加法操作成功,因为 x+y=9+1=10x + y = 9 + 1 = 10,执行该命令后 xx 变为 1010。

mul 10\texttt{mul 10}

1\texttt{1}

对命令 “mul 10” 的响应是 “1”。这表示乘法操作成功,因为 x⋅y=10⋅10=100x \cdot y = 10 \cdot 10 = 100,执行该命令后 xx 变为 100100。

!\texttt{!}

1\texttt{1}

对命令 “!” 的响应是 “1”。这表示你已确认 xx 等于 nn。

5\texttt{5}

在第二个测试用例中,未知整数 x=1234x = 1234,我们需要使其等于 n=5n = 5。

digit\texttt{digit}

1\texttt{1}

对命令 “digit” 的响应是 “1”。这表示 xx 被替换为其各位数字之和 1+2+3+4=101 + 2 + 3 + 4 = 10,执行该命令后 xx 变为 1010。

div 2\texttt{div 2}

1\texttt{1}

对命令 “div 2” 的响应是 “1”。这表示除法操作成功,因为 y=2y = 2 是 x=10x = 10 的一个约数,执行该命令后 xx 变为 xy=102=5\frac{x}{y} = \frac{10}{2} = 5。

!\texttt{!}

1\texttt{1}

对命令 “!” 的响应是 “1”。这表示你已确认 xx 等于 nn。

注意:示例输入与输出中的空行仅为增强可读性,在实际交互中不会出现。

输入解题思路,AI测评打分。不知道怎么写?

首页