Find the prime numbers $p<q<r$ such that $r^2-q^2-p^2$ is a perfect square.

I think the only solution is (2,3,7) but i cannot prove it. The equation would be $r^2-q^2-p^2=k^2$ equivalently $q^2+p^2+k^2=r^2$ which is somehow a classical diophantine equation (of the pythagorean quadruples) which have a parametrization but how do i use it? The problem is from a magazine at 8 th grade and i don't think the solution is supposed to use the general solution.

Actually the general solution of $q^2+p^2+k^2=r^2$ is given by: $ q=a^2+b^2-c^2-d^2$



$r=a^2+b^2+c^2+d^2$ IT would follow that one of the numbers q or p is even and prime, so it is 2.

  • $\begingroup$ Ah, it might be in the Olympiad Corner $\endgroup$ Mar 9 '19 at 19:53
  • $\begingroup$ @amarius8312 I have noticed that you haven't accepted any of the 14 questions you've made on MSE. Please consider accepting the answers you like the most ;) PS: You get 2 extra reputation points whenever you accept an answer $\endgroup$
    – Dr. Mathva
    Mar 29 '19 at 15:05


All prime numbers $p\geq5$ satisfy $p\equiv \pm 1\mod 6$

Therefore, if $p,q,r\geq5$

$$r^2-q^2-p^2\equiv (\pm1)^2-(\pm1)^2-(\pm1)^2\equiv 1-1-1\equiv5\mod 6$$

Observe now, that there's no perfect square with the residue $5$ modulo 6.
This follows from the simple fact that (taking the equations modulo $6$)

$$\begin{array}l 1^2\equiv\color{red}1\\ 2^2\equiv \color{red}4\\ 3^2\equiv9\equiv\color{red}3\\4^2\equiv16\equiv \color{red}4\\5^2\equiv25\equiv \color{red}1 \\6^2\equiv\color{red}0\end{array}$$

Can you end it now?


Your guess is correct: $(2,3,7)$ is the unique solution. There is a simple proof using two basic and easy to verify facts:

  • if $m$ is odd, then $m^2\equiv 1\pmod 4$;
  • if $m$ is not divisible by $3$, then $m^2\equiv 1\pmod 3$.

We proceed as follows.

Write $r^2-p^2-q^2=k^2$ with an integer $k$.

If we had $p>2$, this would imply $p^2\equiv q^2\equiv r^2\equiv 1\pmod 4$, leading to $k^2\equiv r^2-p^2-q^2\equiv 3\pmod 4$, which contradicts the first basic fact above. Thus $p=2$, whence $r^2=q^2+k^2+4$.

If we had $q>3$, this would imply $r^2\equiv q^2\equiv 1\pmod 3$ leading to $k^2\equiv 2\pmod 3$, which contradicts the second basic fact above. Thus $q=3$, and, as a result, $r^2=13+k^2$. Consequently, $(r-k)(r+k)=13$, which is only possible if $r-k=1$ and $r+k=13$. This yields $r=7$, $k=6$.

To summarize, the only solution is $p=2$, $q=3$, $r=7$.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.