Count Beautiful Numbers - Problem
You are given two positive integers l and r. A positive integer is called beautiful if the product of its digits is divisible by the sum of its digits.
Return the count of beautiful numbers between l and r, inclusive.
Example: For number 144, digit product = 1×4×4 = 16, digit sum = 1+4+4 = 9. Since 16 % 9 ≠ 0, 144 is not beautiful.
Input & Output
Example 1 — Small Range
$
Input:
l = 1, r = 10
›
Output:
10
💡 Note:
All single digits 1-9 are beautiful (digit product equals digit sum), plus number 10 (product=0, sum=1, 0%1=0).
Example 2 — Including Zero Digits
$
Input:
l = 10, r = 20
›
Output:
2
💡 Note:
Numbers 10 and 20 are beautiful. 10: product=1×0=0, sum=1+0=1, 0%1=0. 20: product=2×0=0, sum=2+0=2, 0%2=0.
Example 3 — Larger Range
$
Input:
l = 1, r = 100
›
Output:
19
💡 Note:
Beautiful numbers include: all single digits 1-9, plus numbers with 0 digits where the remaining product is divisible by the sum (like 10, 20, 30, 40, 50, 60, 70, 80, 90, 100).
Constraints
- 1 ≤ l ≤ r ≤ 1012
- Both l and r are positive integers
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code