## Task A-3.7.

Determine the prime numbers $p, q, r$ and the natural number $n$ for which

$$
p^{2}=q^{2}+r^{n}
$$

Find all solutions.
## First Solution.

First, note that it is necessary that $p > q$.

In particular, $p \geqslant 3$, so the left side of the equation is odd. Therefore, exactly one of the numbers $q$ and $r$ is even, and one is odd. Since the only even prime number is 2, we have two cases: $q=2$ or $r=2$.

Let's first consider the case $q=2$ and $r>2$. By moving $q^{2}$ to the left side of the equation and applying the difference of squares, we get

$$
(p-2)(p+2)=r^{n}
$$

Since $r$ is prime, it must be that $p-2=r^{a}$ and $p+2=r^{b}$, for some non-negative integers $a < b$. Subtracting these two equations, we get

$$
4 = r^{b} - r^{a} = r^{a}(r^{b-a} - 1)
$$

Since $r$ is a prime number, the only possible value for $r$ is 5 (as $r=2$ would make the right side even, and $r \geq 7$ would make the right side too large). Thus, $r=5$ and $a=0$, $b=1$, which gives us the solution:

$$
p=3, q=2, r=5, n=1
$$

Now, let's consider the case $r=2$. We move $q^{2}$ to the left side of the equation and apply the difference of squares:

$$
(p-3)(p+3)=2^{n}
$$

Again, we conclude that $p-3=2^{a}$ and $p+3=2^{b}$, for some non-negative integers $a < b$ such that $a+b=n$. Subtracting these equations, we get

$$
6=2^{a}-2^{b}=2^{a}\left(2^{b-a}-1\right)
$$

Notice that it must be $a=1$ (for $a=0$, the right side is odd or zero, and for $a \geqslant 2$, the right side is divisible by 4). Substituting this conclusion, we get $2^{b}=8$, so $b=3$, hence $n=4$. From either of the remaining equations, we get another solution:

$$
p=5, q=3, r=2, n=4
$$

Therefore, all solutions to the initial equation $(p, q, r, n)$ are $(3,2,5,1)$ and $(5,3,2,4)$.