Find prime numbers with given property I've been working in the following number theory problem: find all prime numbers $p,q,r$ such that
$$p^2+q^2+r^2-1$$
is a perfect square. Does anyone has some hint for the problem? Thanks in advance.
 A: Note that if $n$ is an odd integer, then $n^2\equiv1\pmod8$, and if $n$ is an even number, then $n^2\equiv0\pmod 4$.
If $p,q,r$ are all odd primes, then $p^2+q^2+r^2-1\equiv2\pmod8$, so it can't be a square. So we may assume $p=2$, and we have $q^2+r^2+3$.
Now if $q,r$ are both odd, then $q^2+r^2+3\equiv5\pmod8$, so it's not a square. So we may assume $q=2$, and we have $r^2+7$.
If $r^2+7=m^2$, then $7=m^2-r^2$, but there is only one way to write $7$ as a difference of two squares, namely, $7=4^2-3^2$. So $r=3$, and we're done.
A: The triple $p=q=2, r = 3$ is the only possible solution (up to reordering). To show this first reduce the expression modulo $4$. Since a square must always be congruent to $0$ or $1$ mod $4$ we get
$$
p^2+q^2+r^2 \equiv 1 \pmod{4} \quad \text{or} \quad p^2+q^2+r^2 \equiv 2 \pmod{4}.
$$
Since any odd number squares to $1 \pmod{4}$ we may assume $p = 2$. Hence we need to find all primes $q,r$ such that $r^2+q^2+3$ is a square. Now reduce the equation mod $3$ to find
$$
r^2 + q^2 \equiv 0 \pmod{3} \quad \text{or} \quad r^2 + q^2 \equiv 1 \pmod{3},
$$
since $0$ and $1$ are the only quadratic residues modulo $3$. Therefore at least one of $q$ or $r$ must be divisible by $3$. Since we assume them to be prime this forces without loss of generality $r = 3$. Finally we look for primes $q$ such that $q^2 + 12$ is a square. The quadratic residues modulo $8$ are $0,1,4$. Reducing mod $8$ therefore gives
$$
q^2  \equiv 4 \pmod{8}  \quad \text{or} \quad q^2  \equiv 5 \pmod{8} \quad \text{or} \quad q^2  \equiv 0 \pmod{8}.
$$
Since $5$ is a non-residue we must have $q^2 \equiv 0 \pmod{8}$ or $q^2 \equiv 4 \pmod{8}$. In either case $q$ must be even. Since we assumed it to be prime it follows $q=2$.
