#C4885. Smallest Number with Given Digit Product
Smallest Number with Given Digit Product
Smallest Number with Given Digit Product
Given a positive integer \(m\), your task is to find the smallest number whose digits multiply to \(m\). The digits must range from 1 to 9 (inclusive). If no such number exists, output \(-1\).
The problem can be formulated as follows: find the smallest number \(N\) such that if the digits of \(N\) are \(d_1, d_2, \ldots, d_k\), then \[ d_1 \times d_2 \times \cdots \times d_k = m \] If there is no sequence of digits (from 1 to 9) that satisfies this equation, return \(-1\).
For instance, when \(m=36\), one solution is \(4\) and \(9\) because \(4 \times 9 = 36\), and the smallest such number is 49. In contrast, if \(m=19\), no combination of digits yields a product of 19, so the answer is \(-1\>.
Note: If \(m = 1\), the output should be 1 since \(1\) is the only number whose digit product is 1.
inputFormat
The input consists of a single line containing a positive integer \(m\).
outputFormat
Output a single line with the smallest number whose digits multiply to \(m\), or \(-1\) if such a number does not exist.
## sample36
49
</p>