Count the Digits That Divide a Number
Real-world version: Digits That Divide The ReadingThe 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.
def dividing_digits(reading: int) -> int:public int dividingDigits(int reading)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 14 test cases: 14 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's