Carlinhos likes to write numbers in his notebook. One day he wrote the numbers from 1 to 999, one after the other, to form the giant number:

$$
123456789101112 \ldots 997998999
$$

About this number, the following questions are asked:

(a) How many digits were written?

(b) How many times does the digit 1 appear?

(c) Considering that 1 occupies position 1, 2 occupies position 2, and 0 appears for the first time occupying position 11, which digit occupies position 2016?
Solution

(a) Observe that we have 9 numbers with one digit each, $99-9=90$ numbers with two digits each, and $999-99=900$ numbers with three digits each. Therefore, the number of digits written is:

$$
9 \cdot 1 + 90 \cdot 2 + 900 \cdot 3 = 2889
$$

(b) Note that the digit 1 appears once among the one-digit numbers. Among the two-digit numbers, the digit 1 appears 10 times as the tens place and 9 times as the units place, totaling 19 times among the two-digit numbers. Among the three-digit numbers, the digit 1 appears 100 times as the hundreds place. Additionally, for each of the 9 different hundreds, the digit 1 appears 10 times as the tens place and 10 times as the units place. Thus, in these numbers, it appears $9 \cdot (10 + 10) = 180$ times. We conclude that the number of appearances of the digit 1 is:

$$
1 + 19 + 100 + 180 = 300
$$

(c) Note that $2016 > 9 + 90 \cdot 2 = 189$, so the digit at position 2016 will appear among the three-digit numbers. Indeed, we can look for the digit $2016 - 189 = 1827$ from the numbers $100101102103 \ldots$... Since $1827 = 3 \cdot 609$, then, being 100 the first number, the last digit of the number in the 609th position will be the digit we are looking for. The number in the 609th position is

$$
100 + 609 - 1 = 708
$$

Thus, we conclude that the digit at position 2016 in this sequence is 8.