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 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 x (1≤x≤109). You must make it equal to a given integer in the input n. 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 y"
−1018≤y≤1018
res=x+y
if 1≤res≤1018
x←res
"1"
else
x←x
"0"
"mul y"
1≤y≤1018
res=x⋅y
if 1≤res≤1018
x←res
"1"
else
x←x
"0"
"div y"
1≤y≤1018
res=x/y
if y divides x
x←res
"1"
else
x←x
"0"
"digit"
—
res=S(x)∗
—
x←res
"1"
You have to make x equal to n using at most 4 commands.
∗S(n) is a function that returns the sum of all the individual digits of a non-negative integer n. For example, S(123)=1+2+3=6
这是该题目的中等难度版本。在此版本中,你最多可以发送 4 条指令。仅当该题所有难度版本均已被解决时,你才可进行 Hack。
这是一道交互式问题。
欢迎各位决斗者!在此交互式挑战中,存在一个未知整数 x(满足 1≤x≤109)。你需要通过操作使其等于输入中给定的整数 n。借助“数学机械”(Mathmech)怪兽的力量,你可以发送以下四种指令之一:
| 指令 | 约束条件 | 结果 | 情况 | 更新 | 评测机响应 |
|---|---|---|---|---|---|
"add $y$" |
−1018≤y≤1018 | res=x+y | 若 1≤res≤1018 | x←res | "1" |
| 否则 | x←x | "0" |
|||
"mul $y$" |
1≤y≤1018 | res=x⋅y | 若 1≤res≤1018 | x←res | "1" |
| 否则 | x←x | "0" |
|||
"div $y$" |
1≤y≤1018 | res=x/y | 若 y 整除 x | x←res | "1" |
| 否则 | x←x | "0" |
|||
"digit" |
— | res=S(x)∗ | — | x←res | "1" |
你必须在最多 4 条指令内使 x 等于 n。
∗ S(n) 是一个函数,返回非负整数 n 的各位数字之和。例如,S(123)=1+2+3=6。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤5000). The description of the test cases follows.
The first and only line of each test case contains one integer n (1≤n≤109).
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤5000)。随后是各测试用例的描述。
每个测试用例仅有一行,包含一个整数 n(1≤n≤109)。
输入输出样例
输入#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
There are 2 test cases.
100
In the first test case, the unknown integer x=9 and we have to make it equal to n=100.
add -10
0
The answer to "add -10" is "0". This means that the addition command was not successful as x+y=9+(−10)≤0, and x remains 9 after the command
add 1
1
The answer to "add 1" is "1". This means that the addition command was successful as x+y=9+1=10, and x changes to 10 after the command.
mul 10
1
The answer to "mul 10" is "1". This means that the multiplication command was successful as x⋅y=10⋅10=100, and x changes to 100 after the command.
!
1
The answer to "!" is "1". This means you have determined that x equals n.
5
In the second test case, the unknown integer x=1234 and we have to make it equal to n=5.
digit
1
The answer to "digit" is "1". This means that x turned into the sum of its digits 1+2+3+4=10, and x changes to 10 after the command.
div 2
1
The answer to "div 2" is "1". This means that the division command was successful as y=2 is a divisor of x=10, and x changes to yx=210=5 after the command.
!
1
The answer to "!" is "1". This means you have determined that x equals n.
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
共有 2 个测试用例。
100
在第一个测试用例中,未知整数 x=9,我们需要使其等于 n=100。
add -10
0
对命令 “add -10” 的响应是 “0”。这表示加法操作失败,因为 x+y=9+(−10)≤0,执行该命令后 x 仍为 9。
add 1
1
对命令 “add 1” 的响应是 “1”。这表示加法操作成功,因为 x+y=9+1=10,执行该命令后 x 变为 10。
mul 10
1
对命令 “mul 10” 的响应是 “1”。这表示乘法操作成功,因为 x⋅y=10⋅10=100,执行该命令后 x 变为 100。
!
1
对命令 “!” 的响应是 “1”。这表示你已确认 x 等于 n。
5
在第二个测试用例中,未知整数 x=1234,我们需要使其等于 n=5。
digit
1
对命令 “digit” 的响应是 “1”。这表示 x 被替换为其各位数字之和 1+2+3+4=10,执行该命令后 x 变为 10。
div 2
1
对命令 “div 2” 的响应是 “1”。这表示除法操作成功,因为 y=2 是 x=10 的一个约数,执行该命令后 x 变为 yx=210=5。
!
1
对命令 “!” 的响应是 “1”。这表示你已确认 x 等于 n。
注意:示例输入与输出中的空行仅为增强可读性,在实际交互中不会出现。
输入解题思路,AI测评打分。不知道怎么写?