#P8361. [SNOI2022] 倍增

    ID: 9452 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>各省省选2022Special JudgeO2优化陕西

[SNOI2022] 倍增

Problem Description

Xiao Z is a girl who likes programming.

One day, while solving a programming problem, she accidentally found a magical integer 142857142857.

142857×2=285714142857 \times 2 = 285714, and all digits of 285714285714 are exactly a permutation of the digits of 142857142857.

She was curious whether there exists a larger integer with this property.

She wrote a search program and found some larger interesting numbers:

26835741×2=5367148226835741 \times 2 = 53671482

0987312654×2=19746253080987312654 \times 2 = 1974625308

\dots

She is not satisfied with only the decimal case. So she wants to know whether, in base BB, there exists an nn-digit positive integer xx such that all digits of 2x2x in base BB are a permutation of all digits of xx in base BB.

Since she hates the digit 00, she also requires that for any 1in1 \leq i \leq n, the ii-th digit of xx and the ii-th digit of 2x2x in base BB cannot both be 00 at the same time.

Input Format

The input contains multiple test cases.

The first line contains a positive integer TT, the number of test cases.

The next TT lines each contain two positive integers nn and BB, describing one test case.

Output Format

For each test case, output one line.

If there is a solution for this test case, output nn non-negative integers from the most significant digit to the least significant digit, representing the value of your answer in base BB.

Otherwise, output a single number 1-1.

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 nn-digit base-BB numbers.
  • For the third test case, the base-77 representation of 2x2x is 103635(7)103635_{(7)}, 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, 1T1041 \leq T \leq 10^4, 2B2×1052 \leq \sum B \leq 2 \times 10^5, 1n2×1051 \leq \sum n \leq 2 \times 10^5, n1n \geq 1, B2B \geq 2.

The detailed constraints are shown in the table below.

Test Point ID nn \leq B B \leq TT \leq Special Constraints
11 88 88 1010
22 10410^4
33 2×1052 \times 10^5 1010
44 10410^4
55
66 1515 100100
77 4040
88 100100
99 300300
1010 10001000
1111 30003000
1212 1500015000
1313 5000050000
1414 2×1052 \times 10^5
1515 200200 10410^4 n100n \geq 100
1616 50005000
1717 2×1052 \times 10^5
1818 300300 B=3k1,kNB=3k-1,k \in \N^*
1919 2×1052 \times 10^5
2020 300300 B=3k,kNB=3k,k \in \N^*
2121 2×1052 \times 10^5
2222 100100
2323 500500 50005000
2424 2×1052 \times 10^5
2525

Translated by ChatGPT 5