#B2082. Count Digit 2 Occurrences in a Range
Count Digit 2 Occurrences in a Range
Count Digit 2 Occurrences in a Range
Given a range ([L,R]) of integers, count the total number of times the digit (2) appears in all the numbers within that range. For example, in the range ([2,22]):
- Number 2 contains 1 occurrence of (2).
- Number 12 contains 1 occurrence of (2).
- Number 20 contains 1 occurrence of (2).
- Number 21 contains 1 occurrence of (2).
- Number 22 contains 2 occurrences of (2).
The total count in this example is 6.
inputFormat
The input consists of two space-separated integers (L) and (R) representing the inclusive bounds of the range.
Example: 2 22
.
outputFormat
Output a single integer which is the total number of times the digit (2) appears in all the numbers from (L) to (R).
sample
2 22
6