Finding all pairs $(a,b)$ of positive integers such that $a^2+nab+b^2$ is a perfect square. When $n=2$, the question is trivial. Is there a general method to find all such pairs for $n\ge{3}$ and $n\in{\mathbb{N}}$?
 A: Let $a^2+nab+b^2 = c^2$
Let $x = \dfrac ac$ and $y=\dfrac bc$.
Then we need to find rational soloutions $(x,y)$ to $x^2 + nxy + y^2 = 1$

We start with the particular solution $(x,y) = (-1,0)$ and "draw" the line 
$y = \dfrac uv(x+1)$, where $u,v$ are integers, through that point. It should intersect the hyperbola $x^2 + nxy + y^2 = 1$ at a rational point.
\begin{align}
   x^2 + nxy + y^2 &= 1 \\
   x^2 + \dfrac uvnx(x+1) + \dfrac{u^2}{v^2}(x+1)^2 &= 1 \\
   x &= \dfrac{v^2-u^2}{u^2+uvn+v^2} &\text{(We discarded $x=-1$.)} \\
   y &= u\dfrac{nu+2v}{u^2+nuv+v^2}
\end{align}
We get  $a^2+nab+b^2 = c^2$ where
\begin{align}
   a &= v^2-u^2 \\
   b &= nu^2+2uv \\
   c &= u^2+nuv+v^2
\end{align}
If $(a,b)$ is a solution, then so too is $(-a,-b)$, $(b,a)$, and $(-b,-a)$. So all solutions can be characterized as
$$\{a,b\} \in \{v^2-u^2, nu^2+2uv\}, \quad c = u^2+nuv+v^2$$
A: Another way to approach this is to use Hilbert's theorem 90.
As in steven gregory's reply aim to solve
$$x^2+nxy+y^2=1$$
in the rationals. This is equivalent to
$$N\left(x+\frac{ny}2+\frac y2\sqrt{n^2-4}\right)=1$$
where $N$ is the norm map from $\Bbb Q(\sqrt{n^2-4})$
to $\Bbb Q$. By Hilbert 90, the norm $1$ elements of the
quadratic field are
$$\frac{u+v\sqrt{n^2-4}}{u-v\sqrt{n^2-4}}
=\frac{(u+v\sqrt{n^2-4})^2}{u^2-(n^2-4)v^2}$$
for rational $u$, $v$ not both zero. We can now grind out
general formulae for $x$ and $y$, which will be equivalent
to steven gregory's
A: 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$$
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.
