## Task B-1.4.

How many natural numbers less than 10000 have exactly three equal digits?

Determine the sum of all such numbers whose unit digit is 1.
## Solution.

The desired numbers can be three-digit or four-digit numbers. These are numbers of the form

$$
1^{\circ} \overline{x x x}, x \neq 0, x \in\{1,2,3,4,5,6,7,8,9\}
$$

There are exactly 9 three-digit numbers where all three digits are the same.

$2^{\circ} \overline{x x x 0}, \overline{x x 0 x}, \overline{x 0 x x}, x \in\{1,2,3,4,5,6,7,8,9\}$

There are $9 \cdot 3=27$ four-digit numbers where three digits are the same and the fourth is 0. (The digit $x$ can be chosen in 9 ways, for each of the 3 possible positions for the digit 0.)

$3^{\circ} \overline{x x x y}, \overline{x x y x}, \overline{x y x x}, \overline{y x x x}, x \neq y, x, y \in\{1,2,3,4,5,6,7,8,9\}$

There are $9 \cdot 8 \cdot 4=288$ four-digit numbers where three digits are the same and the fourth is different from 0.

$4^{\circ} \overline{x 000}, x \in\{1,2,3,4,5,6,7,8,9\}$. There are 9 such numbers.

In total, there are $9+27+288+9=333$ numbers with the desired property.

It is also necessary to calculate the sum of numbers less than 10000 where exactly three digits are the same, and the units digit is 1.

The numbers to be summed can have exactly three ones or exactly one one.

If there are exactly three ones, we calculate the sum of numbers of the form

$$
111, \quad 1101, \quad 1011, \quad \overline{11 x 1}, \quad \overline{1 x 11}, \quad \overline{x 111}
$$

where $x \in\{2,3,4,5,6,7,8,9\}$. The sum of the first three numbers is 2223. The remaining numbers can be summed as

$$
1000 \cdot(1+1+x)+100 \cdot(1+1+x)+10 \cdot(1+1+x)+3 \cdot 1=1110 \cdot(2+x)+3
$$

for all numbers $x \in\{2,3,4,5,6,7,8,9\}$.

Since $2+3+4+5+6+7+8+9=44$, it follows that

$[1110 \cdot(2+2)+3]+[1110 \cdot(2+3)+3]+\cdots+[1110 \cdot(2+9)+3]=1110 \cdot(8 \cdot 2+44)+8 \cdot 3=66624$.

If there is exactly one one, and it is the one in the units place, the numbers are of the form $\overline{x x x 1}$, $x \neq 0,1$. Their sum is

$$
2221+3331+\cdots+9991=44 \cdot 1110+8 \cdot 1=48848
$$

The total sum is $2223+66624+48848=117695$.