#3345
Easy Algorithms Smallest divisible digit product i
Math Enumeration
64.4% acceptance
Feb 23, 2026
72
12
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.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn smallest_number(n: i32, t: i32) -> i32 {
let mut x = n;
loop {
let product: i32 = x.to_string().bytes().map(|b| (b - b'0') as i32).product();
if product % t == 0 { return x; }
x += 1;
}
}
}