Problem

3622. Check Divisibility by Digit Sum and Product

Logic

Code

class Solution {
public:
    bool checkDivisibility(int n) {
        int nc = n;
        int digitSum = 0;
        int digitProduct = 1;

        while (nc != 0) {
            int digit = nc % 10;
            nc /= 10;

            digitSum += digit;
            digitProduct *= digit;
        }

        int divisor = digitSum + digitProduct;

        if (divisor == 0) {
            return false;
        }

        return (!(n % divisor));
    }
};