4. Determine all pairs of integers $(x, y)$ for which there exists a prime number $p$ and an integer $a$ such that $x^{2}+y^{2}=p$ and $(x+y)^{2}-a^{2}=p$.
## 4. Version for Class 4 and Lower

We may assume that $a \geqslant 0$. If $(x, y)$ is a solution, then $(-x, -y)$ is also a solution, so we may assume in the following that $x+y \geqslant 0$ and at the end add the solution $(-x, -y)$ for each found solution $(x, y)$.

We see that

$$
p=(x+y)^{2}-a^{2}=(x+y+a)(x+y-a) .
$$

From this, it follows that $x+y+a$ is not equal to zero. Therefore, $x+y+a$ is positive and $x+y-a$ must also be positive. The prime number $p$ can only be written as a product of two positive integers in two ways: $1 \cdot p$ and $p \cdot 1$. Since $x+y+a \geqslant x+y-a$, it follows that $x+y+a=p$ and $x+y-a=1$. Adding these two equations, we find that $2 x+2 y=p+1$. We also know that $x^{2}+y^{2}+1=p+1$, so $2 x+2 y=x^{2}+y^{2}+1$. By moving all terms to the right side and adding 1 to both sides, we get

$$
1=x^{2}+y^{2}-2 x-2 y+2=(x-1)^{2}+(y-1)^{2} \text {. }
$$

We now have two integer squares that add up to 1. This can only happen if one of the squares is 0 and the other is 1, so $(x-1)^{2}=0$ and $(y-1)^{2}=1$, or $(x-1)^{2}=1$ and $(y-1)^{2}=0$. In the first case, $x-1=0$ and $y-1= \pm 1$, so $(x, y)$ is equal to $(1,2)$ or $(1,0)$. In the second case, $x-1= \pm 1$ and $y-1=0$, so $(x, y)$ is equal to $(2,1)$ or $(0,1)$. Since $0^{2}+1^{2}=1$ is not a prime number, $(1,0)$ and $(0,1)$ are not possible solutions.

We now check if $(1,2)$ and $(2,1)$ are solutions. In both cases, we find $p=x^{2}+y^{2}=1^{2}+2^{2}=5$, and that is indeed a prime number. If we take $a=2$, then $(x+y)^{2}-a^{2}=3^{2}-2^{2}=5$ and that is indeed equal to $p$.

Adding the solutions where $x$ and $y$ are replaced by $-x$ and $-y$ gives a total of four solutions $(x, y)$, namely

$$
(1,2),(2,1),(-1,-2),(-2,-1) \text {. }
$$