## Task 3

A number is called interesting if all its digits are mutually different, and its first digit is equal to the sum of all the other digits. For example, the numbers 321 and 80413 are interesting. How many interesting numbers are there?
## Solution:

First, note that a number can have 3, 4, or 5 digits. It cannot have more, because 0+1+2+3+4=10.

Three-digit numbers:

$3=1+2$

$4=1+3$

$5=1+4=2+3$

$6=1+5=2+4$

$7=1+6=2+5=3+4$

$8=1+7=2+6=3+5$

$9=1+8=2+7=3+6=4+5$

This gives 16 possibilities. However, the order of the second and third digits can be arbitrary, so there are a total of 16 * 2 = 32 interesting three-digit numbers.

For four-digit numbers, we have all 16 combinations as in the three-digit numbers because we can add the addend 0 (e.g., $6=0+2+4$), and we have 7 additional possibilities:

$6=1+2+3$

$7=1+2+4$

$8=1+2+5=1+3+4$

$9=1+2+6=1+3+5=2+3+4$

This gives a total of $16+7=23$ different sums. Each sum yields six interesting numbers because the digits (except the first) can be permuted. Therefore, the total number of interesting four-digit numbers is $23 \cdot 6 = 138$.

For five-digit numbers, combinations without 0 are not possible, because $1+2+3+4>9$.

Thus, we have the same 7 possibilities as for four-digit numbers without zero, and in each possibility, we add 0 (e.g., $8=0+1+3+4$).

Each sum yields 24 interesting numbers because the last 4 digits can be arranged in $4 \cdot 3 \cdot 2 \cdot 1 = 24$ ways. Therefore, the number of interesting five-digit numbers is $7 \cdot 24 = 168$.

In total, there are $168 + 138 + 32 = 338$ interesting numbers.