## Task A-4.5.

Let $n$ be a natural number. In how many ways can we fill an $n \times n$ table with the numbers $1, 2, -1, -2$ such that the product of the numbers in each row is equal to -2 and the product of the numbers in each column is also equal to -2?
## Solution.

For $n=1$, there is obviously one desired way. Let $n>1$ from now on.

In each row and each column, there must be exactly one of the numbers 2 or -2.

We can separately determine the positions in the table where the numbers whose absolute value is 2 will be located and the positions in the table where the negative numbers will be located.

The positions for numbers with an absolute value of 2 can be chosen in $n!$ ways.

In each row (or column), we can arbitrarily choose the sign for $n-1$ numbers, and the remaining number has a uniquely determined sign to ensure the product is negative.

Let $P$ be the part of the table consisting of $(n-1)^2$ cells in the first $n-1$ rows and $n-1$ columns. Further, let $x$ be the number in the $n$-th row and $n$-th column, and let $a_1, \ldots, a_{n-1}$ be the remaining numbers in the $n$-th row, and $b_1, \ldots, b_{n-1}$ be the remaining numbers in the $n$-th column.

![](https://cdn.mathpix.com/cropped/2024_05_30_1a4376e76c5095e3db07g-27.jpg?height=617&width=626&top_left_y=183&top_left_x=635)

Every arrangement of signs for which the product in each column and each row is negative is completely determined by the signs of the numbers in $P$.

Conversely, if we arbitrarily arrange the signs of the numbers in $P$, it is clear from the above that the signs of the numbers

$$
a_1, \ldots, a_{n-1}, b_1, \ldots, b_{n-1}
$$

are uniquely determined.

We still need to determine whether the sign of the number $x$ can be adjusted so that the product in both the $n$-th row and the $n$-th column is negative.

The sign of the number $x$ must be opposite to the sign of the product $a_1 a_2 \ldots a_{n-1}$, and it must also be opposite to the sign of the product $b_1 b_2 \ldots b_{n-1}$. Therefore, it is necessary to check that the signs of the products $a_1 a_2 \ldots a_{n-1}$ and $b_1 b_2 \ldots b_{n-1}$ are the same.

If $n$ is even (or odd), then the product of all numbers in the first $n-1$ columns is negative (or positive). Therefore, the product $a_1 a_2 \ldots a_{n-1}$ and the product of all numbers in $P$ have opposite (or the same) signs if $n$ is even (or odd). The same applies to the product $b_1 b_2 \ldots b_{n-1}$, so the claim from the previous paragraph follows.

Thus, the number of desired arrangements of signs in the entire table is equal to the number of arbitrary arrangements of signs in $P$, which is $2^{(n-1)^2}$.

The final result is $n! \cdot 2^{(n-1)^2}$.