Class Solution
-
- All Implemented Interfaces:
public final class Solution3348 - Smallest Divisible Digit Product II.
Hard
You are given a string
numwhich represents a positive integer, and an integert.A number is called zero-free if none of its digits are 0.
Return a string representing the smallest zero-free number greater than or equal to
numsuch that the product of its digits is divisible byt. If no such number exists, return"-1".Example 1:
Input: num = "1234", t = 256
Output: "1488"
Explanation:
The smallest zero-free number that is greater than 1234 and has the product of its digits divisible by 256 is 1488, with the product of its digits equal to 256.
Example 2:
Input: num = "12355", t = 50
Output: "12355"
Explanation:
12355 is already zero-free and has the product of its digits divisible by 50, with the product of its digits equal to 150.
Example 3:
Input: num = "11111", t = 26
Output: "-1"
Explanation:
No number greater than 11111 has the product of its digits divisible by 26.
Constraints:
<code>2 <= num.length <= 2 * 10<sup>5</sup></code>
numconsists only of digits in the range['0', '9'].numdoes not contain leading zeros.<code>1 <= t <= 10<sup>14</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final StringsmallestNumber(String num, Long t)-
-
Method Detail
-
smallestNumber
final String smallestNumber(String num, Long t)
-
-
-
-