Show problems as
Classic problem #2520EasyMath

Count the Digits That Divide a Number

Real-world version: Digits That Divide The Reading
Tracked in this browser only
Read Count the Digits That Divide a Number on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A meter shows a positive whole number reading.

Walk the decimal digits of reading from left to right. A digit carries when the reading divides by that digit with no remainder. A digit equal to 0 never carries, since nothing divides by zero.

Return how many digit positions carry. A digit that appears more than once is counted once for each position it occupies.

Examples

Example 1

Input
reading = 4620
Output
3

4620 divides evenly by 4, by 6 and by 2, so those three positions carry. The final digit is 0 and never carries.

Example 2

Input
reading = 305
Output
1

305 leaves a remainder of 2 when divided by 3, the middle digit is 0 and cannot carry, and 305 divides evenly by 5. One position carries.

Example 3

Input
reading = 936
Output
3

936 divides evenly by 9, by 3 and by 6, so all three positions carry.

Constraints

  • 1 <= reading <= 10^9

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def dividing_digits(reading: int) -> int:
Java
public int dividingDigits(int reading)