Find all integers satisfying $m^2=n_1^2+n_1n_2+n_2^2$

I need to solve for $(n_1, n_2, m)$ (where $m, n_1, n_2$ are all integers - may be +ve or -ve) satisfying $m^2=n_1^2+n_1n_2+n_2^2$.

I have found 2 solutions so far - $(3, 5, 7)$ and $(7, 8, 13)$. What is a general solution?

UPDATE: For my purpose, it is further needed that $\gcd(n_1, m) = \gcd(n_2, m) = 1 $.


Solution 1:

This equation is symmetric so many solutions.

Generally speaking, this equation has a lot of formulas for the solution. Because it is symmetrical.

Write the formula can someone come in handy. the equation:

$Y^2+aXY+X^2=Z^2$

Has a solution:

$X=as^2-2ps$

$Y=p^2-s^2$

$Z=p^2-aps+s^2$

more:

$X=(4a+3a^2)s^2-2(2+a)ps-p^2$

$Y=(a^3-8a-8)s^2+2(a^2-2)ps+ap^2$

$Z=(2a^3+a^2-8a-8)s^2+2(a^2-2)ps-p^2$

more:

$X=(a+4)p^2-2ps$

$Y=3p^2-4ps+s^2$

$Z=(2a+5)p^2-(a+4)ps+s^2$

more:

$X=8s^2-4ps$

$Y=p^2-(4-2a)ps+a(a-4)s^2$

$Z=-p^2+4ps+(a^2-8)s^2$

For the particular case: $Y^2+XY+X^2=Z^2$ You can draw more formulas.

$X=3s^2+2ps$

$Y=p^2+2ps$

$Z=p^2+3ps+3s^2$

more:

$X=3s^2+2ps-p^2$

$Y=p^2+2ps-3s^2$

$Z=p^2+3s^2$

In the equation: $X^2+aXY+bY^2=Z^2$ there is always a solution and one of them is quite simple.

$X=s^2-bp^2$

$Y=ap^2+2ps$

$Z=bp^2+aps+s^2$

$p,s$ - integers asked us.

Solution 2:

I'll first address the gentleman INDIVID why he prefers, in over 90% of his answers, to give results without proofs or links/reference to sources. One can hardly learn from such methods even if the results are concrete. Given; $m^2=n_1^2+n_1n_2+n_2^2$. We have, $n_1^2+n_1n_2+n_2^2-m^2=0$, a quadratic in $n_1$, hence, for the discriminant we have, $n_2^2-4(n_2^2-m^2)=k^2$ or $(2m)^2-3n_2^2=k^2$ for some integer $k$. Now, all rational pell equation of the above form has solutions given by $(r^2-d)^2=(r^2+d)^2-d(2r)^2$ for any $r$. Hence, by direct comparison, $d=3$, $n_2=2r$, $2m=r^2+3$ and $k=r^2-3$ where $r$ is any odd integer, a condition which ensures $m$ is an integer. Now, $n_1$ must be an integer, since $k$ and $n_2$ have the same parity.