P1980 [NOIP 2013 Junior] Counting Problem

Background

NOIP 2013 Junior T1.

Description

Compute how many times the digit $x$ ($0 \le x \le 9$) appears among all integers from $1$ to $n$. For example, among $1$ to $11$, i.e., in $1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11$, the digit $1$ appears $4$ times.

Input Format

Two integers $n$ and $x$, separated by a single space.

Output Format

One integer, representing the number of times $x$ appears.

Explanation/Hint

For $100\%$ of the testdata, $1 \le n \le 10^6$, $0 \le x \le 9$. Translated by ChatGPT 5