// 演算法 / Algorithm:
// 從 n 開始逐一往上枚舉每個整數 x，計算 x 的各位數字乘積，
// 一旦該乘積能被 t 整除就回傳 x。因為帶 0 的數字乘積為 0（0 能被任何 t 整除），
// 答案一定存在且很快出現。
// Enumerate x upward from n, compute the digit product, return the first x
// whose product is divisible by t. A 0 digit guarantees an answer exists nearby.

int smallestNumber(int n, int t) {
    // 從 n 開始，無限往上找，直到 return 為止
    // Start at n and loop upward forever until we return.
    for (int x = n; ; x++) {
        long long product = 1;   // 乘積初始化為 1（乘法單位元）/ init product to 1 (multiplicative identity)
        int cur = x;             // 用一個副本來拆解位數，保留原本的 x / a copy of x to peel digits from, keeping x intact

        // 反覆取出最右邊一位並乘進 product，直到 cur 變成 0
        // Repeatedly take the last digit and multiply it in, until cur becomes 0.
        while (cur > 0) {
            product *= cur % 10;  // cur % 10 是最右一位；乘進累積乘積 / cur % 10 is the last digit; multiply it in
            cur /= 10;            // 整數除法去掉最右一位（如 123 -> 12）/ integer division drops the last digit (123 -> 12)
        }

        // 若數字乘積能被 t 整除（餘數為 0），x 就是答案
        // If the digit product is divisible by t (remainder 0), x is the answer.
        if (product % t == 0)
            return x;            // 回傳第一個符合的數字 / return the first matching number
    }
}
