Count the Digits That Divide a Number - Problem
Given an integer num, return the number of digits in num that divide num evenly.
A digit val divides num if num % val == 0.
Note: We only consider non-zero digits, as division by zero is undefined.
Example: For num = 1248, the digits are 1, 2, 4, 8. We check: 1248 % 1 = 0 ✓, 1248 % 2 = 0 ✓, 1248 % 4 = 0 ✓, 1248 % 8 = 0 ✓. All 4 digits divide the number, so we return 4.
This problem tests your understanding of digit extraction and modular arithmetic.
Input & Output
example_1.py — Basic Case
$
Input:
num = 7
›
Output:
1
💡 Note:
The only digit is 7, and 7 % 7 = 0, so 7 divides 7. Return 1.
example_2.py — Multiple Digits
$
Input:
num = 1248
›
Output:
4
💡 Note:
Digits are 1, 2, 4, 8. Check: 1248 % 1 = 0, 1248 % 2 = 0, 1248 % 4 = 0, 1248 % 8 = 0. All 4 digits divide 1248.
example_3.py — With Non-Divisible Digits
$
Input:
num = 121
›
Output:
2
💡 Note:
Digits are 1, 2, 1. Check: 121 % 1 = 0 ✓, 121 % 2 = 1 ✗, 121 % 1 = 0 ✓. Only 2 digits divide 121.
Constraints
- 1 ≤ num ≤ 109
- num does not contain 0 as a digit
Visualization
Tap to expand
Understanding the Visualization
1
Component Extraction
Extract each digit component from the product using mathematical operations
2
Quality Test
Test if the component (digit) is compatible with the product (original number)
3
Count Valid Components
Keep track of how many components pass the quality test
4
Final Report
Return the total count of compatible components
Key Takeaway
🎯 Key Insight: Mathematical digit extraction using modulo and division is more efficient than string conversion, providing O(1) space complexity while maintaining O(d) time complexity.
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code