Problem Description
Find the smallest number greater than or equal to n such that the product of its digits is divisible by t.
Key Insights
- We need to find an integer x starting from n such that when you compute the product of its digits, the result is divisible by t.
- A brute-force approach is acceptable given that n is at most 100 and t is at most 10.
- If any digit is 0, the product becomes 0, which will always be divisible by t (since t is non-zero).
- The simple approach is to check each number in sequence and return the first one that satisfies the condition.
Space and Time Complexity
Time Complexity: O(m * d) where m is the number of numbers checked until a solution is found and d is the number of digits in each number. Space Complexity: O(1) since constant extra space is used.
Solution
The solution iterates through the numbers starting at n. For each number, a helper function calculates the product of its digits. This is done either by converting the number to a string or by iterative modulus operations. The product is then checked to see if it is divisible by t. Due to the small input constraints, this brute-force enumeration provides an efficient solution.