## Task 4

How many five-digit numbers divisible by three are there with all distinct digits?
## First solution:

A number is divisible by three if the sum of its digits is divisible by 3.

Let's divide the digits as follows: $\mathrm{A}=\{0,3,6,9\}, \mathrm{B}=\{1,4,7\}, \mathrm{C}=\{2,5,8\}$.

In the first group, the digits are divisible by 3. Any digit from the second group added to any digit from the third group results in a number divisible by three. For a number to be divisible by 3, we have three possibilities for selecting its digits:

a) two digits from sets B and C, one from A,

b) one digit from B and C, three from A,

c) all three digits from B or C and two from A.

We also need to distinguish whether we use the digit 0 or not.

If 0 is not used, under a) we have $3 \cdot 3 \cdot 3=27$ possibilities, under b) $3 \cdot 3 \cdot 1=9$, and under c) $3 \cdot 2=6$. In total, 42.

If 0 is used, under a) we have $3 \cdot 3 \cdot 1=9$ possibilities, under b) $3 \cdot 3 \cdot 3=27$, and under c) $3 \cdot 2=6$. In total, 42.

If the digit 0 is not used, we can permute the digits in $5 \cdot 4 \cdot 3 \cdot 2=120$ ways.

If the digit 0 appears, we have only $5 \cdot 4 \cdot 3 \cdot 2-4 \cdot 3 \cdot 2=120-24=96$ possibilities.

The desired solution is $42 \cdot 120 + 42 \cdot 96 = 9072$.