#P4226. [清华集训 2017] 避难所

    ID: 3155 远端评测题 1000ms 250MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>贪心2017Special Judge构造清华集训

[清华集训 2017] 避难所

Description

For a positive integer nn, we define the product of its digits in base bb as p=F(n,b)p = F(n, b).

For example, F(3338,10)=216F(3338, 10) = 216.

Consider the following task: given pp and bb, find the smallest nn such that p=F(n,b)p = F(n, b).

This problem is quite interesting. For some bases bb, we can solve it greedily. For example, if b=10,p=216b = 10, p = 216, we can try dividing pp by integers from b1b - 1 down to 22 until pp becomes 11. The answer is 389389, and you can verify that 389389 is the smallest nn satisfying p=F(n,b)p = F(n, b).

However, for some bases bb, this greedy approach does not work. For instance, when b=9,p=216b = 9, p = 216, the greedy solution is 33383338, while the optimal answer is 666666 (both in base 99).

In this problem, for a given base bb, either produce such a counterexample or state that no such counterexample exists.

Due to limited computing resources, in any counterexample the product of all digits must not exceed 101810^{18}. If in the smallest counterexample the product of all digits exceeds 101810^{18}, you should output 1-1.

Input Format

Read from standard input.

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

Each of the next tt lines contains an integer bb, the base.

Output Format

Output to standard output.

If no counterexample exists, output a single integer 1-1.

If a counterexample exists, first output an integer kk, the number of digits of nn in the counterexample. Then, on the same line, output kk decimal integers, which represent any optimal solution (the digits of the smallest nn for that counterexample) in base bb.

3
8
9
10
-1
3 6 6 6
-1

Hint

  • For the 1st subtask (30 points), 1b321 \leq b \leq 32.
  • For the 2nd subtask (40 points), 1b1001 \leq b \leq 100.
  • For the 3rd subtask (30 points), 1t200,1b1000001 \leq t \leq 200, 1 \leq b \leq 100000.

Translated by ChatGPT 5