Task 2. Let $n \geq 4$ be an integer. Consider a regular $2 n$-gon where each vertex is assigned an integer, which we call the value of that vertex. If four distinct vertices of this $2 n$-gon form a rectangle, then the sum of the values of these vertices is called a rectangle sum.

Determine for which integers (not necessarily positive) $m$ we can assign the numbers $m+1, m+2$, ..., $m+2 n$ as values to the vertices (in some order) so that every rectangle sum is a prime number. (Prime numbers are by definition positive.)
Solution. Number the vertices of the $2n$-gon clockwise from 1 to $2n$, and let $a_i$ be the value of vertex $i$. Since the number of vertices of the polygon is even, we can pair each vertex with the one directly opposite it. We add the values of each pair of opposite vertices and obtain the numbers $s_i = a_i + a_{i+n}$ for $1 \leq i \leq n$.

If four vertices $A, B, C$, and $D$ form a rectangle in that order, then $\angle ABC = 90^\circ$ and $\angle ADC = 90^\circ$, so $B$ and $D$ lie on the circle with diameter $AC$ according to Thales' theorem. Since all vertices of the polygon lie on its circumscribed circle, $AC$ is clearly a diameter of the circumscribed circle. Thus, $A$ and $C$ are opposite vertices, and the same applies to $B$ and $D$. Conversely, if $A$ and $C$ are opposite vertices and $B$ and $D$ are also, then $ABCD$ is a rectangle, also by Thales' theorem. In short, four points form a rectangle if and only if they belong to two pairs of opposite vertices.

Therefore, it must hold that $s_i + s_j$ is prime for all $1 \leq i < j \leq n$. Suppose at least three of the numbers $s_i$ have the same parity, say $s_j, s_k$, and $s_l$. Then the sum of any two of these three is even, but also prime, so this sum must be 2 in all cases. Thus, $s_j + s_k = s_k + s_l = s_j + s_l$, which implies $s_j = s_k = s_l$. Since $s_j + s_k = 2$, this gives $s_j = s_k = s_l = 1$. We conclude that at most two of the numbers $s_i$ are even, and if there are three or more odd ones, they must all be equal to 1.

The total sum of all $s_i$ is equal to the sum of all the numbers at the vertices, which is

$$
(m+1) + (m+2) + \ldots + (m+2n) = 2mn + \frac{1}{2} \cdot 2n \cdot (2n+1) = 2mn + n(2n+1).
$$

Modulo 2, this sum is congruent to $n$. On the other hand, this sum must be congruent modulo 2 to the number of odd $s_i$. Therefore, the number of odd $s_i$ has the same parity as $n$. Since there are a total of $n$ numbers $s_i$, the number of even $s_i$ is even. We have already seen that there are at most two, so there are either zero or two.

Suppose $n=4$ and suppose there are two even $s_i$ and thus also two odd $s_i$. Then the sum of the two even $s_i$ is 2 and the sum of the two odd $s_i$ is also 2, so the total sum of the $s_i$ is $4 = n$. Now suppose $n \geq 5$ and suppose there are two even $s_i$. Then there are $n-2 \geq 3$ odd $s_i$, so all odd $s_i$ are equal to 1. The two even $s_i$ together are equal to 2. Thus, the total sum of the $s_i$ is $(n-2) + 2 = n$. (You can also prove that the case with exactly two even $s_i$ is impossible.) Now suppose there are no even $s_i$. Then all $s_i$ are odd and thus all equal to 1, so the total sum of the $s_i$ is $n$.

In all cases, the total sum of the $s_i$ is thus $n$. We have also seen that this sum is equal to $2mn + n(2n+1)$. Therefore, $2mn + n(2n+1) = n$, and after dividing by $n \neq 0$, we get $2m + 2n + 1 = 1$, so $m = -n$.

We now show that if $m = -n$, there is indeed a solution. Take $a_i = i$ and $a_{n+i} = 1 - i$ for $1 \leq i \leq n$. Then the numbers $1, 2, \ldots, n$ and the numbers $0, -1, \ldots, -n+1$ are used, and these are precisely the numbers $m+1, m+2, \ldots, m+2n$. Furthermore, $s_i = i + (1 - i) = 1$ for all $i$. Thus, every rectangle sum is equal to 2, which is a prime number.

We conclude that $m = -n$ is the only value of $m$ that satisfies the condition.