Smallest Divisible Digit Product II
You are given a string num that represents a positive integer, and an integer t.
A number is called zero-free when none of its digits is 0.
Return a string that represents the smallest zero-free number greater than or equal to num whose digit product is divisible by t. When no such number exists, return "-1".
The input can hold up to 2 * 10^5 digits and t can be as large as 10^14, so numeric conversion of num and enumeration of consecutive integers are not valid strategies. A digit product built only from digits 1 through 9 can use no prime other than 2, 3, 5 and 7, so any other prime factor of t makes the answer "-1".
Examples
Input: ["10",1]
Output: "11"
Input: ["10",2]
Output: "12"
Hints
Factor `t` into powers of `2`, `3`, `5` and `7`, and reject any remaining factor.
Track `minimum(a, b, c, d)`, the fewest digits from `1` through `9` that cover a residual exponent tuple. Coverage is monotone, so extra factors of a prime are wasted but allowed, and every useful digit lowers the state.
Copy `num` as long as possible. The smallest same-length answer differs from `num` at one rightmost position that holds a larger digit, and its suffix is the smallest digit sequence that fits the leftover slot budget.
Related Problems
Smallest Divisible Digit Product II
You are given a string `num` that represents a positive integer, and an integer `t`.