P1179 [NOIP 2010 Junior] Digit Statistics

Description

Count how many times the digit $2$ appears among all integers in the given range $[L, R]$. For example, for the range $[2, 22]$, the digit $2$ appears 1 time in the number 2, 1 time in 12, 1 time in 20, 1 time in 21, and 2 times in 22, so the digit $2$ appears a total of 6 times in this range.

Input Format

$2$ positive integers $L$ and $R$, separated by a space.

Output Format

The number of occurrences of digit $2$.

Explanation/Hint

Constraints: $1 ≤ L ≤ R ≤ 100000$. NOIP 2010 Junior Problem 1. Translated by ChatGPT 5