#C1756. Count Digit Occurrences
Count Digit Occurrences
Count Digit Occurrences
You are given two integers, \(M\) and \(D\). Your task is to count the total number of occurrences of the digit \(D\) in each integer from 1 to \(M\) (inclusive). In other words, for every integer \(n\) such that \(1 \leq n \leq M\), count how many times the digit \(D\) appears when \(n\) is written in decimal notation.
For example, if \(M = 25\) and \(D = 2\), the digit 2 appears 9 times (in the numbers 2, 12, 20, 21, 22, 23, 24, and 25). Solve this problem by reading the input from stdin and writing the output to stdout.
inputFormat
The input is given via stdin and consists of two integers separated by a space.
- M: a positive integer representing the maximum number (\(1 \leq M \leq 10^6\)).
- D: a single digit (0-9) whose occurrences are to be counted.
outputFormat
Output a single integer to stdout representing the number of times the digit \(D\) appears in all the numbers from 1 to \(M\) (inclusive).
## sample25 2
9