Smallest Divisible Digit Product I - Problem
You are given two integers n and t.
Return the smallest number greater than or equal to n such that the product of its digits is divisible by t.
For example, if n = 15 and t = 3, we need to find the smallest number ≥ 15 where the product of digits is divisible by 3. The number 16 has digit product 1×6 = 6, which is divisible by 3, so the answer is 16.
Input & Output
Example 1 — Basic Case
$
Input:
n = 15, t = 3
›
Output:
16
💡 Note:
Starting from 15: digit product = 1×5 = 5, not divisible by 3. Next number 16: digit product = 1×6 = 6, which is divisible by 3, so return 16.
Example 2 — Zero Digit
$
Input:
n = 19, t = 7
›
Output:
20
💡 Note:
Starting from 19: digit product = 1×9 = 9, not divisible by 7. Next number 20: digit product = 2×0 = 0, which is divisible by 7, so return 20.
Example 3 — Answer is n itself
$
Input:
n = 12, t = 2
›
Output:
12
💡 Note:
Starting from 12: digit product = 1×2 = 2, which is divisible by 2, so return 12 itself.
Constraints
- 1 ≤ n ≤ 106
- 1 ≤ t ≤ 106
Visualization
Tap to expand
Understanding the Visualization
1
Input
Given n=15, t=3, find smallest number ≥ 15
2
Process
Check digit products: 15→5, 16→6
3
Output
Return 16 (first with digit product divisible by 3)
Key Takeaway
🎯 Key Insight: Iterate from n upwards checking digit products until finding one divisible by t
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code