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

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

4 Answers 4


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:


Has a solution:
















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








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




$p,s$ - integers asked us.

  • 2
    $\begingroup$ Did you explain why this gives us ALL the solutions? $\endgroup$ Commented Jun 1, 2014 at 6:24
  • 1
    $\begingroup$ 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/… $\endgroup$
    – individ
    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.

  • $\begingroup$ 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. $\endgroup$
    – hola
    Commented Jun 1, 2014 at 7:34
  • $\begingroup$ $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$ $\endgroup$
    – user145342
    Commented Jun 1, 2014 at 10:17

Method $1$

The remarkable equation $x^2 + pxy + y^2 = z^2$ where $p$ is a fixed 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.

  • $\begingroup$ And why this answer gave? I wrote this formula. $\endgroup$
    – individ
    Commented Feb 19, 2015 at 4:10
  • 3
    $\begingroup$ 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. $\endgroup$
    – Elaqqad
    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


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



After solving for t we get

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






You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .