## Task B-3.4.

While waiting in line for tickets, Klara passed the time by writing down natural numbers in sequence on a piece of paper, starting from the number 1. In doing so, she did not write down any numbers that contained the digit 3. The last number she wrote before it was her turn was 9999.

How many digits in total does the number that Klara obtained by this writing have? What is the 2019th digit in the sequence?
## Solution.

The number $N=12456789101112141516 \ldots 999799989999$.

To calculate the total number of digits in the number $N$, we need to determine how many natural numbers less than 10000 do not contain the digit 3 in their notation.

At the beginning, there are 8 single-digit numbers: $1,2,4,5,6,7,8,9$.

There are $8 \cdot 9=72$ two-digit numbers that do not contain the digit 3, as the first digit can be chosen in 8 ways (it cannot be 0 or 3), and the second in 9 ways (it cannot be 3, but it can be 0). This gives us $2 \cdot 72=144$ digits in the sequence.

Similarly, there are $8 \cdot 9 \cdot 9=648$ three-digit numbers that do not contain the digit 3, giving us 1944 digits in the sequence.

There are $8 \cdot 9 \cdot 9 \cdot 9=5832$ four-digit numbers that do not contain the digit 3, which gives us 23328 digits.

Thus, the number $N$ has a total of $8+144+1944+23328=25424$ digits.

We also need to determine the 2019th digit in the sequence.

By the time we have written all the three-digit numbers with the desired property, we have written $8+144+1944=2096$ digits. This means that the 2096th digit is the last digit of the number 999, so we will look for the 2019th digit among the three-digit numbers.

Thus, we need to go back 2096 - 2019 = 77 digits, which is 25 three-digit numbers and 2 more digits. Since from 990 to 999, from 980 to 989, and from 970 to 979 there are 9 numbers each that do not contain the digit 3, going back 27 numbers will bring us to the last digit of the number 969. Since $2096 - 3 \cdot 9 = 2015$, this is the 2015th digit.

The next three digits are the digits of the number 970, so the 2019th digit is the first digit of the number 971, which is the digit 9.