4. Let $n$ be an even natural number. We partition the numbers $1,2, \ldots, n^{2}$ into two sets $A$ and $B$ of equal size, such that each of the $n^{2}$ numbers belongs to exactly one of the two sets. Let $S_{A}$ and $S_{B}$ be the sum of all elements in $A$ and $B$ respectively. Determine all $n$ for which there exists a partition such that

$$
\frac{S_{A}}{S_{B}}=\frac{39}{64}
$$

Answer: The natural numbers $n$ sought are all multiples of 206.
Let $k$ be the integer such that $S_{A}=39 k$ and $S_{B}=64 k$. We then have that the sum of all numbers from 1 to $n^{2}$ is

$$
\frac{n^{2}\left(n^{2}+1\right)}{2}=S_{A}+S_{B}=39 k+64 k=103 k
$$

Thus, $103 \left\lvert\, \frac{n^{2}\left(n^{2}+1\right)}{2}\right.$, and since 103 is a prime number, it must divide either $\frac{n^{2}}{2}$ or $n^{2}+1$. However, since $n^{2}$ and $1=1^{2}$ are coprime, all prime divisors of $n^{2}+1$ must be congruent to $1 \bmod 4$. Since $103 \equiv 3 \bmod 4$, it cannot divide $n^{2}+1$ and thus must be a divisor of $\frac{n^{2}}{2}$. This can only be the case if $103 \mid n$, so since $n$ must be even, there can only be a solution if $n$ is a multiple of 206.

Now let's show that if $n=206 m$ for some natural number $m$, such a partition exists. In this case we have

$$
k=\frac{S_{A}+S_{B}}{103}=\frac{n^{2}\left(n^{2}+1\right)}{206}
$$

and it suffices to show that we can choose half of the numbers so that their sum is $39 k$. In fact, in this case, the sum of the remaining numbers would necessarily be $64 k$. We prove here a stronger property, namely that all sums from $\frac{n^{2}\left(n^{2}+2\right)}{8}$ to $\frac{3 n^{4}+2 n^{2}}{8}$ are achievable. Since $\frac{n^{2}\left(n^{2}+2\right)}{8}=\frac{103 k}{4}\frac{n^{2}\left(n^{2}+2\right)}{8}$, the set $A$ must contain a number greater than $\frac{n^{2}}{2}$ and thus $B$ must contain a number less than or equal to $\frac{n^{2}}{2}$. In particular, this means that there is a number in $A$ that is strictly greater than a number in $B$. Therefore, there exists a number $x$ such that $x \in B$ and $x+1 \in A$. By swapping $x$ and $x+1$, the sum in $A$ decreases by 1, which proves that it is indeed possible to achieve all sums.