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$.

• @Tito Piezas would be a good person to consult here Commented Mar 19 at 22:14

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.

• Did you explain why this gives us ALL the solutions? Commented Jun 1, 2014 at 6:24
• The method of calculation must be shown. I still can't do it. Part of these formulae is the consequence of more complex formulas. Can this topic show. math.stackexchange.com/questions/738446/… Commented Jun 1, 2014 at 6:37

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.

• It is not clear why $n_1^2$ in this case is a perfect square. You have not also mentioned what do you mean by 'of the above form', I mean the exact form of the equation.
– hola
Commented Jun 1, 2014 at 7:34
• $n_1$ need not be a perfect square but the discriminant of the quadratic in $n_1$ need be a perfecr square, for from $n_1^2+n_1(n_2)+(n_2^2-m^2)=0$ we have $2n_1=-n_2 p\m \sqrt(4m^2-3n_2^2)$ so that necessarily, $(4m^2-3n_2^2)=k^2$ a perfect square. For you second question; given the integer $d$, any equation of the form $x^2-dy^2=z^2$ has the general, integer, solutions $x=r^2+d$, $y=2r$ and $z=r^2-d$ for any integer $r$ Commented Jun 1, 2014 at 10:17

Method $$1$$

The remarkable equation $$x^2 + pxy + y^2 = z^2$$ where $$p$$ is a ﬁxed integer. The well-known pythagorean equation is obtained for $$p = 0$$, and your question for $$p=1$$.

The solutions of this equation has been completely determined, all integral solutions to this equation are given by: $$x = k(pn^2 −2mn)$$ $$y = k(m^2 −n^2)$$ $$z = k(pmn−m^2 −n^2)$$ where k,m,n are integral parameters.

Method $$2$$ We can notice that your equation is equivalent to $$(2n_1+n_2)^2+3n_2^2=(2m)^2$$ The solutions of the equation $$x^2+3y^2=z^2$$ are also completely determined, see for example here, otherwise there is a generalization here.

• And why this answer gave? I wrote this formula. Commented Feb 19, 2015 at 4:10
• In all your answers,you give results without proofs or links/reference to sources, here I include some resources for the proofs, because we don't want a lot of formulas. we want to solve an equation and in this case we need a proof (if you want a collection of formulas you can find them here:sites.google.com/site/tpiezas/005b ) but the most important thing is some explication explaining how did you find this formulas, and if you don't have a complete answer (the complete solution of the given question) don't answer it let professionals do it. Commented Feb 19, 2015 at 13:04

I am changing variables

Let $$X^2+XY+Y^2 = Z^2$$ such that X,Y,Z are all Integers and gcd(X,Z) = gcd(Y,Z)=1

Consider $$X^2+XY+Y^2 = Z^2$$

Divdiding by $$Y^2$$ on both sides for above equation

Let

$$t=\frac{X}{Y}$$ & $$u=\frac{Z}{Y}$$

After Substituting $$t,u$$ we get

$$t^2+t+1 = u^2$$

Now we need to solve this Diophantine equation for rational solutions

Put

$$u=\frac{nt+m}{n}$$

After solving for t we get

$$t=\frac{n^2-m^2}{2mn-n^2}=\frac{X}{Y}$$ &

$$u=\frac{n^2+m^2-mn}{2mn-n^2}=\frac{Z}{Y}$$

$$X=n^2-m^2$$

$$Y=2mn-n^2$$

$$Z=n^2+m^2-mn$$