Divisibility by Combined Digit Values

Quick Overview

Check whether a positive integer is divisible by the sum of its decimal digit sum and digit product. Include zero digits in the product and return a boolean for the combined divisor.

Divisibility by Combined Digit Values

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

# Divisibility by Combined Digit Values Given a positive integer `n`, let `S` be the sum of its decimal digits and `P` be the product of those digits. Return whether `n` is divisible by `S + P`. The test uses the sum of these two values, rather than separate divisibility tests for `S` and `P`. ### C++ Interface ```cpp class Solution { public: bool checkDivisibility(int n); }; ``` ### Examples **Example 1** ```text n = 120 Output: true ``` The digit sum is `1 + 2 + 0 = 3`, and the digit product is `1 * 2 * 0 = 0`. Their sum is three, which divides 120. **Example 2** ```text n = 34 Output: false ``` The digit sum is seven and the product is twelve, giving divisor nineteen. Dividing 34 by nineteen leaves remainder fifteen. ### Constraints - `1 <= n <= 1000000`. - Digits are from the ordinary decimal representation of `n`. ### Clarifying Questions - Does a zero digit contribute to the product? Yes. If any digit is zero, the product is zero. - Should the function divide by the digit product alone? No. The required divisor is digit sum plus digit product. - Are negative inputs or the value zero included? No. The input is positive. - Is the return value a divisor or quotient? Neither; return a boolean indicating exact divisibility. ### What a Strong Answer Covers - The sum and product of all original decimal digit occurrences. - Correct treatment of zero digits and single-digit inputs. - Exact divisibility by the combined value `S + P`. - Safe arithmetic and resource bounds for inputs up to one million. ### Follow-up Questions - Does containing a zero digit guarantee a true result? Give a counterexample if not. - What result do the permitted single-digit inputs produce? ```hint Preserve the original number Extract digits from a copy of n. Initialize the sum to zero and the product to one, then test the original n modulo the sum of those two accumulated values. ```

Overview: Check whether a positive integer is divisible by the sum of its decimal digit sum and digit product. Include zero digits in the product and return a boolean for the combined divisor.

Google logo
Google
Source window: 0–3 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Divisibility by Combined Digit Values

Given a positive integer n, let S be the sum of its decimal digits and P be the product of those digits.

Return whether n is divisible by S + P. The test uses the sum of these two values, rather than separate divisibility tests for S and P.

C++ Interface

class Solution {
public:
    bool checkDivisibility(int n);
};

Examples

Example 1

n = 120
Output: true

The digit sum is 1 + 2 + 0 = 3, and the digit product is 1 * 2 * 0 = 0. Their sum is three, which divides 120.

Example 2

n = 34
Output: false

The digit sum is seven and the product is twelve, giving divisor nineteen. Dividing 34 by nineteen leaves remainder fifteen.

Constraints

  • 1 <= n <= 1000000 .
  • Digits are from the ordinary decimal representation of n .

Clarifying Questions Guidance

  • Does a zero digit contribute to the product? Yes. If any digit is zero, the product is zero.
  • Should the function divide by the digit product alone? No. The required divisor is digit sum plus digit product.
  • Are negative inputs or the value zero included? No. The input is positive.
  • Is the return value a divisor or quotient? Neither; return a boolean indicating exact divisibility.

What a Strong Answer Covers Guidance

  • The sum and product of all original decimal digit occurrences.
  • Correct treatment of zero digits and single-digit inputs.
  • Exact divisibility by the combined value S + P .
  • Safe arithmetic and resource bounds for inputs up to one million.

Follow-up Questions Guidance

  • Does containing a zero digit guarantee a true result? Give a counterexample if not.
  • What result do the permitted single-digit inputs produce?