5. Filling a $3 \times 3$ table with numbers from 1 to 9 is called a magic square if each number is used exactly once, and the sums in each row, each column, and both diagonals are all equal. Determine how many different magic squares $3 \times 3$ exist. (Two magic squares are considered different if they have different numbers in at least one cell.)

## Third Grade - B Category
5. Let's consider the magic square as shown in the left image. Since $a+b+c+\cdots+i=1+2+3+\cdots+9=45$ and $a+b+c=d+e+f=g+h+i$, it follows that $a+b+c=d+e+f=g+h+i=15$, and the sums in each row and on both diagonals are 15. Notice now:

![](https://cdn.mathpix.com/cropped/2024_06_04_841f52b4ffb037ad799bg-54.jpg?height=149&width=180&top_left_y=1175&top_left_x=1150)

| 2 | 9 | 4 |
| :--- | :--- | :--- |
| 7 | 5 | 3 |
| 6 | 1 | 8 |

Ok 2018 2B 5

$60=4 \cdot 15=(b+e+h)+(d+e+f)+(a+e+i)+(c+e+g)=(a+b+c+\cdots+i)+3 e=45+3 e$,

from which it follows that $e=5$.

Suppose the number 9 is placed in a corner; without loss of generality, let $a=9$. Then from $15=a+b+c=a+d+g$ it follows that $b+c=d+g=6$. However, notice that two numbers can sum to 6 only if they are 2 and 4 (indeed, the possibility $3+3$ is ruled out because the numbers must be distinct, and the possibility $1+5$ is ruled out because the number 5 is already used for $e$), so we have actually reached a contradiction.

Therefore, the number 9 cannot be placed in a corner, and must be in the middle of a side. For example, let $b=9$. Then similarly as before, we get $a+c=6$, i.e., $a=2$ and $c=4$ or vice versa. Whichever of these two possibilities we choose (and they are mutually analogous), it is easy to see that the rest of the magic square can be filled in a unique way (the filling on the right is shown for $a=2$ and $c=4$).

Thus, the number 5 must always be in the center, and then the number 9 can be written in the middle of a side, which gives 4 possibilities for the number 9. After writing the number 9, we have another choice for which of its two neighbors will be 2 and which will be 4, which are 2 more possibilities, and further filling of the magic square is uniquely determined. Therefore, the total number of different $3 \times 3$ magic squares is $4 \cdot 2=8$.

## Third Grade - B Category