#C5580. Digit Product Number
Digit Product Number
Digit Product Number
Given an integer P, find the smallest positive integer N whose digits have a product equal to P. More formally, if the digits of N are represented as \(d_1, d_2, \dots, d_k\), then they must satisfy:
\(d_1\times d_2\times \cdots \times d_k = P\)
If no such number exists, output -1
.
Note: If P is a single digit (P < 10) and not equal to 1, then the answer is P itself. For P equals 1, the answer is 1.
For example:
- If P = 36, then the smallest number whose digits multiply to 36 is 49.
- If P = 10, the answer is 25.
- If P = 29, the answer is -1 (since no combination of digits yields 29 as a product).
inputFormat
The input is provided via stdin and consists of a single integer P on one line.
outputFormat
Output the smallest digit product number that satisfies the condition. If no such number exists, output -1
. The result should be printed to stdout.
36
49