Back to Month
EASY 22 Aug 2026 View on LeetCode

3622. Check Divisibility by Digit Sum and Product

</> Solution

class Solution {
    public boolean checkDivisibility(int n) {
        int sum = 0, product = 1;
        int temp = n;
        while (temp > 0) {
            int digit = temp % 10;
            sum += digit;
            product *= digit;
            temp /= 10;
        }
        return n % (sum + product) == 0;
    }
}

TIME COMPLEXITY

O(log n)

SPACE COMPLEXITY

O(1)

TOPICS

Math Number Theory Simulation