0% found this document useful (0 votes)
0 views

Problem - C2 - Codeforces

The document describes an interactive problem from Codeforces Round 1025 (Div. 2) where participants must manipulate an unknown integer x to equal a given integer n using at most four commands. Commands include addition, multiplication, division, and digit summation, each with specific constraints and expected responses. The problem emphasizes the importance of command validity and the consequences of exceeding command limits or making invalid commands.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Problem - C2 - Codeforces

The document describes an interactive problem from Codeforces Round 1025 (Div. 2) where participants must manipulate an unknown integer x to equal a given integer n using at most four commands. Commands include addition, multiplication, division, and digit summation, each with specific constraints and expected responses. The problem emphasizes the importance of command validity and the consequences of exceeding command limits or making invalid commands.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

5/17/25, 8:15 PM Problem - C2 - Codeforces

gbsk12345 | Logout

HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS HACKS ROOM STANDINGS CUSTOM INVOCATION

Codeforces Round 1025 (Div. 2)


C2. Hacking Numbers (Medium Version)
Contest is running
time limit per test: 2 seconds
memory limit per test: 256 megabytes 02:04:22

This is the medium version of the problem. In this version, you can send at most 4 Contestant
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 𝑥 (1 ≤ 𝑥 ≤ 10 ).


9
→ Submit?
You must make it equal to a given integer in the input 𝑛. By harnessing the power of
"Mathmech" monsters, you can send a command to do one of the following: Language: GNU GCC C11 5.1.0

Jury's Choose
Command Constraint Result Case Update file:
Choose File No file chosen
response
Be careful: there is 50 points penalty for
if 1 ≤ res ≤ 1018 𝑥 ← res "1" submission which fails the pretests or
"add 𝑦 " −1018 ≤ 𝑦 ≤ 1018 res = 𝑥 + 𝑦 resubmission (except failure on the first test,
else 𝑥←𝑥 "0" denial of judgement or similar verdicts).
"Passed pretests" submission verdict doesn't
if 1 ≤ res ≤ 1018 𝑥 ← res "1" guarantee that the solution is absolutely
"mul 𝑦 " 1≤ 𝑦 ≤ 1018 res = 𝑥⋅𝑦 correct and it will pass system tests.
else 𝑥←𝑥 "0"
Submit
if 𝑦 divides 𝑥 𝑥 ← res "1"
"div 𝑦 " 1≤ 𝑦 ≤ 1018 res = 𝑥/𝑦
else 𝑥←𝑥 "0"
→ Score table
res = 𝑆 (𝑥)
"digit" — ∗ — 𝑥 ← res "1" Score
Problem A 480
You have to make 𝑥 equal to 𝑛 using at most 4 commands. Problem B 960
∗𝑆(𝑛) is a function that returns the sum of all the individual digits of a non-negative integer 𝑛. For example, Problem C1 1200
𝑆(123) = 1 + 2 + 3 = 6
Problem C2 720
Input
Each test contains multiple test cases. The first line contains the number of test cases 𝑡 ( Problem C3 480
1 ≤ 𝑡 ≤ 5000). The description of the test cases follows. Problem D 1680

The first and only line of each test case contains one integer 𝑛 (1 ≤ 𝑛 ≤ 10 9
). Problem E 2400

Problem F 2880
Interaction
The interaction for each test case begins by reading the integer 𝑛. Successful hack 100

Unsuccessful hack -50


To send a command, output a line in the following format:
Unsuccessful submission -50
"add 𝑦 " Add some integer 𝑦 (−1018 ≤ 𝑦 ≤ 1018 ) to 𝑥.
Resubmission -50
The jury will output "1" if 𝑥 + 𝑦 is within [1, 1018 ] (successful), and "0" otherwise. If
successful, update 𝑥 ← 𝑥 + 𝑦. * If you solve problem on 00:10 from the first attempt

"mul 𝑦 " Multiply 𝑥 by a positive integer 𝑦 (1 ≤ 𝑦 ≤ 1018 ).


The jury will output "1" if 𝑥 ⋅ 𝑦 is within [1, 10 ] (successful), and "0" otherwise. If
18

successful, update 𝑥 ← 𝑥 ⋅ 𝑦.
"div 𝑦 " Divide 𝑥 by a positive integer 𝑦 (1 ≤ 𝑦 ≤ 1018 ).

https://codeforces.com/contest/2109/problem/C2 1/3
5/17/25, 8:15 PM Problem - C2 - Codeforces
The jury will output "1" if 𝑦 is a divisor of 𝑥 (successful), and "0" otherwise. If successful,
update 𝑥 ← 𝑥𝑦 .
"digit" Make 𝑥 equal to the sum of its digits.
The jury will always output "1" and update 𝑥 ← 𝑆 (𝑥) .

Note that commands are case sensitive.

When you have determined that 𝑥 is equal to 𝑛, output a line in the following format:

"!" — where the jury will output a "1" if 𝑛 is equal to 𝑥, and "-1" otherwise.

Note that answering does not count toward your limit of 4 commands.

If your program makes more than 4 commands for one test case, or makes an invalid command,
then the response to the command will be "-1". After receiving such a response, your program
should immediately terminate to receive the verdict Wrong Answer. Otherwise, it may receive
any other verdict.

After printing a command, do not forget to output the end of the line and flush the output.
Otherwise, you will get Idleness limit exceeded. To do this, use:

fflush(stdout) or cout.flush() in C++;


System.out.flush() in Java;
sys.stdout.flush() in Python;
std::io::stdout().flush() in Rust;
see the documentation for other languages.

The interactor is non-adaptive. The unknown integer 𝑥 does not change during the interaction.

Hacks

To hack, use the following format.

The first line should contain a single integer 𝑡 (1 ≤ 𝑡 ≤ 5000) — the number of test cases.
The first line of each test case should contain two positive integers 𝑛 and 𝑥 (1 ≤ 𝑛, 𝑥 ≤ 10 ) —
9

denoting the unknown integer and the target value to which it should be made equal,
respectively.
Example
input Copy
2
100

output Copy

add -10

add 1

mul 10

digit

https://codeforces.com/contest/2109/problem/C2 2/3
5/17/25, 8:15 PM Problem - C2 - Codeforces
div 2

Note

Solution Jury Explanation

𝟸 There are 2 test cases.

In the first test case, the unknown integer 𝑥 = 9 and we have to make it
𝟷𝟶𝟶 equal to 𝑛 = 100.

The answer to "add -10" is "0". This means that the addition command
𝚊𝚍𝚍 -𝟷𝟶 𝟶 was not successful as 𝑥 + 𝑦 = 9 + (−10) ≤ 0, and 𝑥 remains 9 after the
command

The answer to "add 1" is "1". This means that the addition command
𝚊𝚍𝚍 𝟷 𝟷 was successful as 𝑥 + 𝑦 = 9 + 1 = 10 , and 𝑥 changes to 10 after the
command.

The answer to "mul 10" is "1". This means that the multiplication
𝚖𝚞𝚕 𝟷𝟶 𝟷 command was successful as 𝑥 ⋅ 𝑦 = 10 ⋅ 10 = 100 , and 𝑥 changes to
100 after the command.
The answer to "!" is "1". This means you have determined that 𝑥 equals
! 𝟷
𝑛.
In the second test case, the unknown integer 𝑥 = 1234 and we have to
𝟻 make it equal to 𝑛 = 5.

The answer to "digit" is "1". This means that 𝑥 turned into the sum of
𝚍𝚒𝚐𝚒𝚝 𝟷 its digits 1 + 2 + 3 + 4 = 10 , and 𝑥 changes to 10 after the command.

The answer to "div 2" is "1". This means that the division command
𝚍𝚒𝚟 𝟸 𝟷 was successful as 𝑦 = 2 is a divisor of 𝑥 = 10 , and 𝑥 changes to
𝑥 = 10 = 5 after the command.
𝑦 2

The answer to "!" is "1". This means you have determined that 𝑥 equals
! 𝟷
𝑛.
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.

Codeforces (c) Copyright 2010-2025 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: May/17/2025 20:15:33UTC+5.5 (k2).
Desktop version, switch to mobile version.
Privacy Policy | Terms and Conditions

Supported by

https://codeforces.com/contest/2109/problem/C2 3/3

You might also like