#K84047. Smallest Product Number
Smallest Product Number
Smallest Product Number
Given a positive integer (N), find the smallest positive integer (M) such that the product of its digits equals (N). Formally, if (M) has digits (d_1, d_2, \ldots, d_k), then it must satisfy
(d_1 \times d_2 \times \cdots \times d_k = N).
If there is no such positive integer, output -1
.
Examples:
- For (N = 18), one possible answer is (29) since (2 \times 9 = 18).
- For (N = 36), one possible answer is (49) since (4 \times 9 = 36).
- For (N = 1), the answer is (1) by definition.
Your program should read input fromstdin
and print the answer tostdout
.
inputFormat
The input consists of a single line containing one integer (N) ((1 \le N \le 10^9) or as constrained by the problem).
outputFormat
Output a single integer (M) — the smallest positive integer satisfying the condition that the product of its digits equals (N), or -1
if no such number exists.## sample
18
29
</p>