#P8361. [SNOI2022] 倍增
[SNOI2022] 倍增
Problem Description
Xiao Z is a girl who likes programming.
One day, while solving a programming problem, she accidentally found a magical integer .
, and all digits of are exactly a permutation of the digits of .
She was curious whether there exists a larger integer with this property.
She wrote a search program and found some larger interesting numbers:
She is not satisfied with only the decimal case. So she wants to know whether, in base , there exists an -digit positive integer such that all digits of in base are a permutation of all digits of in base .
Since she hates the digit , she also requires that for any , the -th digit of and the -th digit of in base cannot both be at the same time.
Input Format
The input contains multiple test cases.
The first line contains a positive integer , the number of test cases.
The next lines each contain two positive integers and , describing one test case.
Output Format
For each test case, output one line.
If there is a solution for this test case, output non-negative integers from the most significant digit to the least significant digit, representing the value of your answer in base .
Otherwise, output a single number .
3
6 10
3 3
6 7
1 4 2 8 5 7
-1
0 3 5 3 1 6
样例 2 见附件 double2.in
本组数据满足测试点 3 的限制。
样例 2 见附件 double2.ans
样例 3 见附件 double3.in
本组数据满足测试点 17 的限制。
样例 3 见附件 double3.ans
Hint
[Sample 1 Explanation]
- The explanation of the first test case can be found in the Description.
- For the second test case, you can prove that such a positive integer cannot be found by enumerating all -digit base- numbers.
- For the third test case, the base- representation of is , so this is a valid answer.
Note that the sample output only shows one possible valid answer, and it does not mean the sample output must exactly match the output of the standard solution.
[Sample 2/3 Explanation]
Note that the sample output only shows one possible valid answer, and it does not mean the sample output must exactly match the output of the standard solution.
[Hint]
Since the answer may not be unique, we provide a checker checker.cpp and a library file testlib.h.
You can compile checker.cpp using the following command:
g++ -o checker checker.cpp -O2 -std=c++11
After compiling checker.cpp into an executable file checker, you can test your output as follows:
checker <input> <output> <answer>: the files double/double*.ans under the contestant directory can be used to verify the correctness of your output on the sample test points double/double*.in.
checker <input> <output> <output>: it will check whether all outputs you claim to have solutions satisfy the problem requirements. Note that in this testing mode, reporting no solution will always be judged as valid, because in this mode we only check all solutions you output.
Please pay attention to clearing data structures between multiple test cases.
[Constraints and Conventions]
For all testdata, , , , , .
The detailed constraints are shown in the table below.
| Test Point ID | Special Constraints | |||
|---|---|---|---|---|
Translated by ChatGPT 5