Exercise 5. a) Find all integers $m \geqslant 1$ and $n \geqslant 1$ such that $\frac{5^{m}+2^{n+1}}{5^{m}-2^{n+1}}$ is the square of an integer.

b) More generally, find all integers $m \geqslant 1$ and $n \geqslant 1$, as well as the prime numbers $p$, such that $\frac{5^{m}+2^{n} p}{5^{m}-2^{n} p}$ is the square of an integer.
## Solution to Exercise 5 a) See Exercise 2 above.

b) Suppose $p=5$. Then $\frac{5^{m-1}+2^{n}}{5^{m-1}-2^{n}}$ is the square of an integer. From part a) (which also works for integers $\geqslant 0$), we have $m=n=2$.

Suppose finally $p \neq 2$ and $p \neq 5$. Let $d$ be the GCD of $5^{m}+2^{n} p$ and $5^{m}-2^{n} p$. Then $d$ divides $5^{m}+2^{n} p+5^{m}-2^{n} p=2 \times 5^{m}$. Since $d$ is the GCD of two odd numbers, it is odd, so it divides $5^{m}$.

Moreover, $d$ divides $5^{m}+2^{n} p-\left(5^{m}-2^{n} p\right)=2^{n+1} p$ and it is odd, so it divides $p$. Since $p$ and 5 are coprime, we deduce that $d=1$ and that $5^{m}-2^{n} p=1$; furthermore, $5^{m}+2^{n} p=a^{2}$ for some integer $a$.

We thus have $(a-1)(a+1)=a^{2}-1=2^{n+1} p$.

The GCD of $a-1$ and $a+1$ divides $(a+1)-(a-1)=2$, so it is 1 or 2. Moreover, $a-1$ and $a+1$ are of the same parity, and their product is even, so their GCD is 2. We deduce that $\left(a-1=2, a+1=2^{n} p\right)$ or $\left(a-1=2 p, a+1=2^{n}\right)$ or $\left(a-1=2^{n}, a+1=2 p\right)$.

In the first case, we would have $a=3$, so $4=a+1=2^{n} p$, which is impossible.

In the second case, we have $p=2^{n-1}-1$. Since $p$ is prime, $n=1$ and $n=2$ do not work, so $n \geqslant 3$. Consequently, $5^{m}=2^{n} p+1 \equiv 1[8]$. Since $5^{2 \ell+1}=5 \times 25^{\ell} \equiv 5 \times 1^{\ell}=5[8]$, the integer $m$ must be even. Let $m=2 \ell$, then $\left(5^{\ell}-1\right)\left(5^{\ell}+1\right)=2^{n} p$. One of the factors is equal to $2 p$ and the other to $2^{n-1}$. Since their difference is 2, we have $\pm 2=2 p-2^{n-1}=2 p-(p+1)=p-1$, so $p=3, n=3$ and $m=2$.

In the third case, we have $p=2^{n-1}+1$. We cannot have $n=1$, otherwise $p=2$. If $n=2$ then $p=3$ and $5^{m}=1+2^{n} p=13$. Impossible. Therefore, $n \geqslant 3$. The same reasoning as above leads to $m=2 \ell$ with $\pm 2=2 p-2^{n-1}=2 p-(p-1)=p+1$, which contradicts $p \geqslant 3$.