## Task A-3.7.

In how many ways can the numbers from 1 to 9 be written in a $3 \times 3$ table so that the sums of the numbers in each row, each column, and each diagonal are divisible by 3?
## Solution.

Since the conditions in the problem are given for divisibility by 3, it is sufficient to consider the remainders that the numbers $1, 2, 3, \ldots, 9$ in the table give when divided by 3. More precisely, instead of the table in which we write the numbers from 1 to 9, we will consider tables in which we write three numbers 0, three numbers 1, and three numbers 2, and further under the condition that the sum of the elements in each row, column, and diagonal is divisible by 3, and we will count how many such tables there are. Let's call these new tables.

Let's calculate the relationship between the number of tables described in the problem and the new tables. Each remainder from the set $\{0, 1, 2\}$ appears three times in the table and represents one of the three numbers from the set from 1 to 9. The total number of ways to replace one of the three remainders with numbers from 1 to 9 can be chosen in 3 ways, and then in 2 ways we choose how the two remaining remainders represent the two remaining numbers that give the same remainder. Thus, we conclude that for each remainder from the set $\{0, 1, 2\}$, the total number of new tables must be multiplied by a factor of 6. Finally, the number of tables described in the problem is equal to the number of new tables multiplied by $6^3$.

Now let's determine the number of new tables. First, we notice that in each row, column, or diagonal, in order for the sum to be divisible by 3, either three different numbers or three identical numbers can be located.

Consider the first row of the table. First, let's count the new tables in which all the numbers in that row are different. Assume that these are the numbers $0, 1, 2$ in order. In the first position of the second row, then any number from the set $\{0, 1, 2\}$ can be written, and it uniquely determines the element in the last row of the first column (due to the sum of the elements in the first column), then the element in the middle of the table (due to the sum on the diagonal), and then all elements in the table.

The tables we obtained are:

| 0 | 1 | 2 |
| :--- | :--- | :--- |
| 0 | 1 | 2 |
| 0 | 1 | 2 |

![](https://cdn.mathpix.com/cropped/2024_05_30_21f39afeb1dfc245d841g-19.jpg?height=231&width=237&top_left_y=290&top_left_x=835)

| 0 | 1 | 2 |
| :--- | :--- | :--- |
| 2 | 0 | 1 |
| 1 | 2 | 0 |

If we assume that in the first row there is any other order of three different numbers (there are 6 in total), we similarly get three new tables similar to the above (by swapping the roles of the numbers $0, 1, 2$ in the entire table). Therefore, the total number of new tables in which three different numbers are located in the first row is $6 \cdot 3 = 18$.

Now let's count the new tables in which all the numbers in the first row are the same. Then, in order for the other rows to have a sum divisible by three, all rows contain three identical numbers. The number of ways to choose the number that will be repeated in the first row is 3, and in 2 ways we then choose the number in the second row (the number in the last row is uniquely determined by the first two rows). Therefore, the total number of new tables in which three identical numbers are located in the first row is $3 \cdot 2 = 6$.

In total, there are $6 + 18 = 24$ new tables, so the total number of tables sought in the problem text is $24 \cdot 6^3 = 5184$.

## SCHOOL/CITY COMPETITION IN MATHEMATICS

4th grade - high school - A variant
February 5, 2022.

## IF A STUDENT HAS A DIFFERENT APPROACH TO SOLVING THE PROBLEM, THE COMMITTEE IS OBLIGED TO GRADE AND EVALUATE THAT APPROACH IN AN APPROPRIATE MANNER.