Smallest Number Factor
Given a number N, find the smallest number S such that the product of its digits is N. Practice factorization and digit manipulation.
Find the smallest number S such that the product of its digits is N.
🎯 Problem Statement
Given a number N, find the smallest number S such that the product of its digits is N. If no such number exists, return -1.
💡 Key Concepts
Digit Factorization
Try to factor N using digits from 9 to 2. The more you use smaller digits, the smaller the resulting number.
Impossible Cases
If N cannot be broken down into digits 2-9, then no such number exists.
📋 Algorithm Pseudo Code
function smallestNumberWithProduct(N):
if N == 0:
return 10
if N == 1:
return 1
factors = ""
for d from 9 down to 2:
while N % d == 0:
factors = d.toString() + factors
N = N / d
if N > 1:
return -1 // Impossible
return factors🔍 Example
Input: N = 1000
Step 1: Factorize 1000 using digits 9-2 → factors = "5558"
Step 2: Build string: "5" + "5" + "5" + "8" = "5558"
Result: 5558
⏱️ Complexity Analysis
Time Complexity
O(log N) - Factorization loop
Space Complexity
O(log N) - For storing factors
1. You are given a number N
2. Find the smallest number S
3. Such that product of digits of S = N
4. Enter your answer and submit
5. Complete all levels to win!