Show problems as
Classic problem #3345EasyMathEnumeration

Smallest Divisible Digit Product I

Real-world version: Next Shelf Label
Tracked in this browser only
Read Smallest Divisible Digit Product I on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A stockroom numbers its shelves with positive whole numbers. A shelf label is valid for a crate of type t when the product of the label's decimal digits is a multiple of t.

The next free shelf is n, and the crate may be placed on shelf n or on any higher-numbered shelf. Return the smallest label at or above n that is valid for t.

A label containing the digit 0 has a digit product of 0, and 0 counts as a multiple of every positive t.

Examples

Example 1

Input
n = 15, t = 7
Output
17

Shelf 15 has digit product 5 and shelf 16 has digit product 6, neither of which is a multiple of 7. Shelf 17 has digit product 7.

Example 2

Input
n = 16, t = 10
Output
20

Shelves 16 through 19 have digit products 6, 7, 8 and 9. Shelf 20 has digit product 0, which counts as a multiple of 10.

Example 3

Input
n = 99, t = 9
Output
99

Shelf 99 has digit product 81, and 81 is 9 times 9.

Constraints

  • 1 <= n <= 100
  • 1 <= t <= 10

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def smallest_shelf_label(n: int, t: int) -> int:
Java
public int smallestShelfLabel(int n, int t)