Check if a Number is Harshad
Given a positive integer n, return true if n is divisible by the sum of its decimal digits; otherwise return false. A number with this property is called a…
Given a positive integer `n`, return `true` if `n` is divisible by the sum of its decimal digits; otherwise return `false`. A number with this property is called a Harshad or Niven number. For example, the digit sum of `18` is `1 + 8 = 9`, and `18` is divisible by `9`.
- `1 ≤ n ≤ 10^9` - `n` is always a positive integer.
Example 1: input n = 18; output true. The digit sum is 9 and 18 mod 9 is 0.
Example 2: input n = 21; output true. The digit sum is 3 and 21 mod 3 is 0.
Example 3: input n = 19; output false. The digit sum is 10 and 19 mod 10 is 9.
Category: Math. Topic: math. Difficulty: Easy. Patterns: math.