## Task B-4.5.

Mare has chosen 6 different digits from the set $\{1,2,3,4,5,6,7,8\}$. Using these digits, she wrote down on paper all possible six-digit numbers where the digits do not repeat. If $S$ is the sum of all the written numbers, determine the largest prime divisor of the number $S$.
## Solution.

For some selection of 6 different digits, Mare could write a total of $6!=720$ numbers.

Let $a, b, c, d, e$ and $f$ be the six selected digits from the set $\{1,2,3,4,5,6,7,8\}$. In the writing of the numbers, each of these digits appears in the place of the hundred-thousands, ten-thousands, thousands, hundreds, tens, and units, exactly $720 / 6=120$ times. For example, if the digit $a$ is in the units place, the remaining digits can be arranged in $5!=120$ ways.

Then the sum of all the written numbers is

$$
\begin{aligned}
S= & 120(a+b+c+d+e+f) \cdot 100000 + 120(a+b+c+d+e+f) \cdot 10000 + \\
& +120(a+b+c+d+e+f) \cdot 1000 + 120(a+b+c+d+e+f) \cdot 100 + \\
& +120(a+b+c+d+e+f) \cdot 10 + 120(a+b+c+d+e+f) = \\
= & 120(a+b+c+d+e+f) \cdot 111111
\end{aligned}
$$

If we factorize the number 120 and the number 111111 into prime factors, we get

$$
S=2^{3} \cdot 3 \cdot 5(a+b+c+d+e+f) \cdot 3 \cdot 7 \cdot 11 \cdot 13 \cdot 37
$$

The sum of the digits $a+b+c+d+e+f$ is a number that must be less than or equal to the number $3+4+5+6+7+8=$ 33, so the largest prime factor that this expression could generate is 31.

We conclude that 37 is the largest prime divisor of the sum $S$.