#P4226. [清华集训 2017] 避难所
[清华集训 2017] 避难所
Description
For a positive integer , we define the product of its digits in base as .
For example, .
Consider the following task: given and , find the smallest such that .
This problem is quite interesting. For some bases , we can solve it greedily. For example, if , we can try dividing by integers from down to until becomes . The answer is , and you can verify that is the smallest satisfying .
However, for some bases , this greedy approach does not work. For instance, when , the greedy solution is , while the optimal answer is (both in base ).
In this problem, for a given base , 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 . If in the smallest counterexample the product of all digits exceeds , you should output .
Input Format
Read from standard input.
The first line contains an integer , the number of test cases.
Each of the next lines contains an integer , the base.
Output Format
Output to standard output.
If no counterexample exists, output a single integer .
If a counterexample exists, first output an integer , the number of digits of in the counterexample. Then, on the same line, output decimal integers, which represent any optimal solution (the digits of the smallest for that counterexample) in base .
3
8
9
10
-1
3 6 6 6
-1
Hint
- For the 1st subtask (30 points), .
- For the 2nd subtask (40 points), .
- For the 3rd subtask (30 points), .
Translated by ChatGPT 5
京公网安备 11011102002149号