#P1980. Count the Occurrence of a Digit

    ID: 15262 Type: Default 1000ms 256MiB

Count the Occurrence of a Digit

Count the Occurrence of a Digit

Given two integers \( n \) and \( x \), count the total number of times the digit \( x \) appears in all integers from \( 1 \) to \( n \) (inclusive). The digit \( x \) satisfies \( 0 \le x \le 9 \). For example, when \( n = 11 \) and \( x = 1 \), the digit \( 1 \) appears 4 times (in the numbers 1, 10, and 11).

inputFormat

The input consists of two integers \( n \) and \( x \) separated by a space.

\( n \): The end of the range (\( 1 \) to \( n \)).
\( x \): A digit (\( 0 \le x \le 9 \)).

outputFormat

Output a single integer representing the total number of times the digit \( x \) appears in all numbers from 1 to \( n \).

sample

11 1
4