luogu#P8412. 「SvR-1」Hack Function!
「SvR-1」Hack Function!
Background
Problem Number:
Little C is sitting at the contest site of J-PSC2077 (the problem can be downloaded from the "Attachments" section below). He is already over seventy years old, but as a player on Team Z, he still managed to participate successfully.
Problem Description
Now J-PSC has finally changed to the CF contest format. Little C quickly got an AK on Day 1. He found that T2 function is quite easy to hack, and the “human-language” translation of the problem is as follows:
For a number , define the function as follows:
- First convert into a base- number .
- Replace with the sum of digits of .
- Repeat Step 1 until becomes a single-digit number.
- Let denote the value of at this time (in decimal). Then . is called the digit-sum function of with respect to .
Given , compute .
In particular, when , output .
Little C solved this problem instantly. When he looked through other people’s code, he found they all used brute-force enumeration (because their machines run extremely fast).
After much effort, he finally saw one person whose code did not contain a single ! But because the testdata was too weak, he still passed.
Little C suddenly got excited and forgot how to construct hack testdata, so he asked you for help through Luogu 6.0.
Little C will tell you the values of and . You need to construct a pair so that the answer outputs .
If it is impossible to construct, output two .
Input Format
This problem contains multiple test cases.
The first line contains an integer , indicating the number of test cases.
The next lines each contain two integers , with meanings as described above.
Output Format
Output lines. For each test case, output the you constructed.
If there are multiple solutions, output any one of them.
3
10 13
10 3
2 1
2 3
-1 -1
1 1
Hint
Explanation of Sample 1
- For test case , under , we have and . Obviously, when , the original problem should output .
- For test case , under , it turns out that it is impossible to meet the requirement.
- For test case , under , it is clear that . This sample is only for understanding. According to the constraints and conventions, we guarantee .
Constraints and Conventions
$$\newcommand{\arraystretch}{1.5} \begin{array}{c|c|c|c}\hline\hline \textbf{Subtask} & \textbf{Description} & \textbf{Time Limit} & \textbf{Score} \\\hline \textsf{1} & \text{No solution} & 1\text{ s} & 3 \\\hline \textsf{2} & \text{A solution exists and \textbf{\textsf{there exists}} a solution with }1\le l\le r\le 10^5 & 1\text{ s} & 16 \\\hline \textsf{3} & 1\le p\le 10^7 & 1\text{ s} & 34 \\\hline \textsf{4} & \text{No special restrictions} & 1.5\text{ s} & 47 \\\hline\hline \end{array}$$For of the testdata: , , .
The time limit is guaranteed to be more than times the runtime of the standard solution (std).
Judging Notes
This problem uses Special Judge and bundled tests.
You must ensure that or and ; otherwise, the SPJ will judge your answer as points.
Translated by ChatGPT 5