Given a positive integer a, find the smallest positive integer whose digits multiply to a.
If there is no answer, or the answer does not fit in the range of a 32-bit signed integer, return 0.
Function Signature
def smallest_factorization(a: int) -> int:
Rules
-
The product of the digits of the returned number must equal
a
exactly.
-
Return
0
when no positive integer has digit product
a
, or when the smallest one is greater than
2147483647
(that is,
2^31 - 1
).
-
For
a = 1
the answer is
1
.
Constraints
Examples
Input: a = 48
Output: 68
48 = 6 * 8, so the smallest number whose digits multiply to 48 is 68. No one-digit number works, and no two-digit number below 68 has digit product 48.
Input: a = 15
Output: 35
15 = 3 * 5, so the smallest number whose digits multiply to 15 is 35.
Input: a = 774840978
Output: 0
774840978 is 2 * 9^9, which needs at least ten digits, and the smallest number with that digit product is 2999999999. That is larger than 2147483647, so the answer is 0.