#B2154. Count the Number of Digit One
Count the Number of Digit One
Count the Number of Digit One
Given a positive decimal integer \( n \), write down all the integers from \( 1 \) to \( n \), and count the total number of times the digit 1
appears.
For example:
- When \( n = 2 \), writing the numbers
1
and2
results in the digit1
appearing once. - When \( n = 12 \), writing the numbers from
1
to12
results in the digit1
appearing 5 times.
Your task is to count the occurrences of the digit 1
in all numbers from \( 1 \) to \( n \).
inputFormat
The input consists of a single positive integer \( n \) provided on one line.
outputFormat
Output a single integer that represents the total count of the digit 1
in the numbers from \( 1 \) to \( n \).
sample
2
1