TITLE: Diophantine equation: $x^2+y^2+z^2=n(xy+yz+zx)$
QUESTION [12 upvotes]: Let $x,y,z\in \mathbb{Z}$. Find all naturals $n$ such that the equation $x^2+y^2+z^2=n(xy+yz+zx)$ has nontrivial solution(s) (i.e. other than $(0,0,0)$), or prove there exist none.
Note: I have proved it for these cases: 
- when $n$ is divisible by a prime
- when $n=4k+3$ for any nonnegative integer $k$.
It seems that there are no nontrivial solutions for $n>1$, but I cannot prove this.

REPLY [5 votes]: Responding to Paolo Leonetti, here are the steps to complete the square. I am not adding to the main answer as the post is already rather lengthy.  
1.1 Factor $x$ variables
Group the $x$ variables:
\begin{align*}
(x^2-nxy-nxz)+y^2-nyz+z^2=0\\
(x^2-n(y+z)x)+y^2-nyz+z^2=0
\end{align*}
Complete the square (and clear denominators)
\begin{align*}
(x^2-n(y+z)x+\left(\dfrac{n(y+z)}{2}\right)^2-\left(\dfrac{n(y+z)}{2}\right)^2)+y^2-nyz+z^2=0\\
4(x^2-n(y+z)x+\left(\dfrac{n(y+z)}{2}\right)^2-\left(\dfrac{n(y+z)}{2}\right)^2)+4y^2-4nyz+4z^2=0\\
(4x^2-4n(y+z)x+(n(y+z))^2)-(n(y+z))^2+4y^2-4nyz+4z^2=0\\
(2x-n(y+z))^2-(n^2(y^2+2yz+z^2))+4y^2-4nyz+4z^2=0
\end{align*}
Let $Z=2x-n(y+z)\Leftrightarrow x=\dfrac{Z+n(y+z)}{2}$, then
$$Z^2-n^2y^2-2n^2yz-n^2z^2+4y^2-4nyz+4z^2=0$$
Note: So I chose to use $Z$ here when getting rid of $x$. I don't even know why. It just... happened.
1.2 Factor $y$ variables
Group $y$ variables:
\begin{align*}
Z^2+(4y^2-n^2y^2-2n^2yz-4nyz)+(4z^2-n^2z^2)=0\\
Z^2+((4-n^2)y^2-(2n^2+4n)yz)+(4-n^2)z^2=0
\end{align*}
Make coefficients of $y^2$ a square:
\begin{align*}
(4-n^2)Z^2+(4-n^2)((4-n^2)y^2-2(n^2+2n)yz)+(4-n^2)^2z^2=0\\
(4-n^2)Z^2+((4-n^2)^2y^2-2(n^2+2n)(4-n^2)yz)+(4-n^2)^2z^2=0
\end{align*}
Complete the square:
\begin{align*}
(4-n^2)Z^2+((4-n^2)^2y^2-2(n^2+2n)(4-n^2)yz+(n^2+2n)^2z^2-(n^2+2n)^2z^2)+(4-n^2)^2z^2=0\\
(4-n^2)Z^2+((4-n^2)y-(n^2+2n)z)^2-(n^2+2n)^2z^2+(4-n^2)^2z^2=0\\
(4-n^2)Z^2+((4-n^2)y-(n^2+2n)z)^2+((4-n^2)^2-(n^2+2n)^2)z^2=0
\end{align*}
Let $Y=(4-n^2)y-(n^2+2n)z\Leftrightarrow y=\dfrac{Y+(n^2+2n)z}{4-n^2}$, then
$$(4-n^2)Z^2+Y^2+((4-n^2)^2-(n^2+2n)^2)z^2=0$$
1.3 Factor $z$ variables
\begin{align*}
(4-n^2)Z^2+Y^2+((4-n^2)^2-(n^2+2n)^2)z^2=0\\
(4-n^2)Z^2+Y^2+(((2-n)(2+n))^2-(n(n+2))^2)z^2=0\\
(4-n^2)Z^2+Y^2+((2-n)^2(n+2)^2-n^2(n+2)^2)z^2=0\\
(4-n^2)Z^2+Y^2+((2-n)^2-n^2)(n+2)^2z^2=0\\
(4-n^2)Z^2+Y^2+(4-4n+n^2-n^2)(n+2)^2z^2=0\\
(4-n^2)Z^2+Y^2+(4-4n)(n+2)^2z^2=0\\
(4-n^2)Z^2+Y^2+(1-n)(4(n+2)^2z^2)=0\\
(4-n^2)Z^2+Y^2+(1-n)(2(n+2)z)^2=0
\end{align*}
Let $X=2(n+2)z\Leftrightarrow z=\dfrac{X}{2(n+2)}$, then
$$(4-n^2)Z^2+Y^2+(1-n)X^2=0$$
$$(n^2-4)Z^2-Y^2+(n-1)X^2=0$$
2. Birational isomorphism
Let
$$C: x^2+y^2+z^2-n(xy+xz+yz)=0$$
and
$$F: (n-1)X^2-Y^2+(n^2-4)Z^2=0$$
We have shown that there is a rational map $\phi$:
$$\phi: C\to F$$
$$(x,y,z)\mapsto \left(2(n+2)z,(4-n^2)y-(n^2+2n)z,2x-n(y+z)\right)$$
We can also find an inverse:
$$z=\dfrac{X}{2(n+2)}$$
$$y=\dfrac{Y+(n^2+2n)z}{4-n^2}=\dfrac{2Y+2n(n+2)z}{2(4-n^2)}=\dfrac{2Y+nX}{2(4-n^2)}$$
$$x=\dfrac{Z+n(y+z)}{2}=\dfrac{2(n+2)(Z+ny+nz)}{4(n+2)}=\dfrac{2(n+2)Z+2n(n+2)y+2n(n+2)z}{4(n+2)}=\dfrac{(2-n)2(n+2)Z+(2-n)2n(n+2)y+(2-n)nX}{(2-n)4(n+2)}=\dfrac{2(4-n^2)Z+2n(4-n^2)y+n(2-n)X}{4(4-n^2)}=\dfrac{2(4-n^2)Z+n(2Y+nX)+n(2-n)X}{4(4-n^2)}=\dfrac{2(4-n^2)Z+2nY+2nX}{4(4-n^2)}=\dfrac{(4-n^2)Z+nY+nX}{2(4-n^2)}$$
so that the inverse rational map is
$$\psi: F\to C$$
$$(X,Y,Z)\mapsto \left(\dfrac{(4-n^2)Z+nY+nX}{2(4-n^2)},\dfrac{2Y+nX}{2(4-n^2)},\dfrac{X}{2(n+2)}\right)$$
The important thing here is to note that this is only undefined at $n=\pm 2$, which suggests that we handle these cases separately.