luogu#P8412. 「SvR-1」Hack Function!

    ID: 7144 远端评测题 1000~1500ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2022洛谷原创Special JudgeO2优化构造洛谷月赛

「SvR-1」Hack Function!

Background

Problem Number: 63\textit{63}

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 AA, define the function f(A)f(A) as follows:

  1. First convert AA into a base-kk number BB.
  2. Replace AA with the sum of digits of BB.
  3. Repeat Step 1 until BB becomes a single-digit number.
  4. Let xx denote the value of AA at this time (in decimal). Then f(A)=xf(A) = x. f(A)f(A) is called the digit-sum function of AA with respect to kk.

Given k,l,r,pk, l, r, p, compute i=lrf(ii)modp\sum_{i = l}^r f(i^i) \bmod p.

In particular, when i=lrf(ii)=p\sum_{i = l}^r f(i^i) = p, output perfect\texttt{perfect}.

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 perfect\texttt{perfect}! 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 kk and pp. You need to construct a pair (l,r)(l, r) so that the answer outputs perfect\texttt{perfect}.

If it is impossible to construct, output two -1\texttt{-1}.

Input Format

This problem contains multiple test cases.

The first line contains an integer TT, indicating the number of test cases.

The next TT lines each contain two integers k,pk, p, with meanings as described above.

Output Format

Output TT lines. For each test case, output the l,rl, r 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 11, under k=10k = 10, we have f(22)=f(4)=4f(2^2) = f(4) = 4 and f(33)=f(27)=9f(3^3) = f(27) = 9. Obviously, when l=2,r=3l = 2, r = 3, the original problem should output perfect\texttt{perfect}.
  • For test case 22, under k=10k = 10, it turns out that it is impossible to meet the requirement.
  • For test case 33, under k=2k = 2, it is clear that f(11)=1f(1^1) = 1. This sample is only for understanding. According to the constraints and conventions, we guarantee k10k \geq 10.

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 100%100\% of the testdata: 10k10310 \leq k \leq 10^3, 1p1081 \leq p \leq 10^8, 1T101 \leq T \leq 10.

The time limit is guaranteed to be more than 44 times the runtime of the standard solution (std).

Judging Notes

This problem uses Special Judge and bundled tests.

You must ensure that l=r=1l = r = -1 or 1lr10181 \leq l \leq r \leq 10^{18} and rl1015r - l \leq 10^{15}; otherwise, the SPJ will judge your answer as 00 points.

Translated by ChatGPT 5