8. Andrei likes all numbers that are not divisible by 3, and Tanya likes all numbers that do not contain digits divisible by 3.

a) How many four-digit numbers are liked by both Andrei and Tanya?

b) Find the total sum of the digits of all such four-digit numbers.
Answer: a) 810; b) 14580.

Solution. a) The required numbers must be composed of the digits $1,2,4,5,7,8$, and according to the divisibility rule by 3, the sum of the digits in each number should not be divisible by three. The digits 1, 4, and 7 (let's call them the digits of set $A$) give a remainder of 1 when divided by 3, while the digits $2,5,8$ (digits of set $B$) give a remainder of 2. Therefore, a number satisfying the condition must be composed in one of the following ways:

1) 4 digits from set $A$ - there are $3^{4}$ such numbers;
2) 4 digits from set $B$ - there are $3^{4}$ such numbers;
3) 3 digits from set $A$ and one digit from set $B$ - there are $4 \cdot 3^{4}$ such numbers;
4) 3 digits from set $B$ and one digit from set $A$ - there are $4 \cdot 3^{4}$ such numbers.

In total, there are $10 \cdot 3^{4}=810$ such numbers.

b) To find the total sum of the digits of all these numbers, we will divide them into pairs: the second number is obtained from the first by replacing all digits according to the principle $1 \leftrightarrow 8,2 \leftrightarrow 7,4 \leftrightarrow 5$. For example, the number 1545 has a pair 8454, the number 5271 has a pair 4728, and so on. The sum of the digits of any pair is $9 \cdot 4$, and the number of such pairs is $\frac{10 \cdot 3^{4}}{2}$. Therefore, the required sum of all digits is $\frac{9 \cdot 4 \cdot 10 \cdot 3^{4}}{2}=20 \cdot 3^{6}=14580$.

Answer to variant 2: a) 160; b) 2880.

Answer to variant 3: a) 810; b) 14580.

Answer to variant 4: a) 160; b) 2880.