#P1179. Counting Digit Two in a Range
Counting Digit Two in a Range
Counting Digit Two in a Range
Given a range \([L, R]\), count the total number of times the digit 2
appears in all the integers within the range.
For example, for the range \([2, 22]\):
- The integer
2
contains1
occurrence of the digit2
. - The integer
12
contains1
occurrence of the digit2
. - The integer
20
contains1
occurrence of the digit2
. - The integer
21
contains1
occurrence of the digit2
. - The integer
22
contains2
occurrences of the digit2
.
Thus, the total count is \(1+1+1+1+2=6\).
inputFormat
The input consists of two integers \(L\) and \(R\) (\(0 \leq L \leq R \leq 10^{9}\)), separated by a space, representing the range \([L, R]\).
outputFormat
Output a single integer representing the total number of times the digit 2
appears in all the integers within the range.
sample
2 22
6