Digit frequency
InterviewTime limit2sMemory limit512 MB
Count how many times a given digit d appears when writing every integer from 1 to n.
- Level
Easy3 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Write down every integer from 1 to in order. Write a program that counts how many times the single digit appears in what you wrote.
For example, with and you write 1 2 3 4 5 6 7 8 9 10 11. The digit 1 appears once in 1, once in 10, and twice in 11, so its frequency is 4.
Input
The first line contains a natural number () and a single digit (), separated by one space.
Output
Print on the first line how many times the digit appears across all the numbers written from 1 to .