Integer solutions of $3a^2 - 2a - 1 = n^2$ I've got an equation $3a^2 - 2a - 1 = n^2$, where $a,n \in \mathbb{N}$.
I put it in Wolfram Alpha and besides everything else it gives integer solution: see here.
For another equation (say, $3a^2 - 2a - 2 = n^2$, where $a,n \in \mathbb{N}$) Wolfram Alpha does not provide integer solutions: here.
Could you please tell me:


*

*How does Wolfram Alpha determine existence of the integer solutions?

*How does it find them?

*What should I learn to be able to do the same with a pencil and a piece of paper (if possible)?


Thanks in advance!
 A: The first one can also be easely reduced to pytagorean one:
$$3a^2 - 2a - 1= 4a^2-(a^2+2a+1) \,.$$
Thus
$$n^2+(a+1)^2=(2a)^2 \,.$$
A: I believe Pell's Equation (and variants) would be useful.
The first one can be recast as
$$9a^2 - 6a - 3 = 3n^2$$ i.e. 
$$(3a-1)^2 - 4 = 3n^2$$
You are looking for solutions to
$$ x^2 - 3y^2 = 4$$ such that $x = -1 \mod 3$.
There are standard techniques to solve Pell's equation and variants (see the wiki page linked above and mathworld page here: http://mathworld.wolfram.com/PellEquation.html) and I am guessing Wolfram Alpha is using one of them.
For the second I believe we get
$$x^2 - 3y^2 = 7$$
which does not have solutions, considering modulo $4$ (as pointed out by Adrián Barquero).
A: Lagrange showed how to reduce a general binary quadratic Diophatine equation to Pell form.
$$\rm a\ x^2 + b\ xy + c\ y^2 + d\ x + e\ y + f\ =\ 0 $$
reduces to a Pell equation as follows: put $\rm\ D = b^2-4ac,\ E = bd-2ae,\ F = d^2-4af\:.\ $ Then
$$\rm  D\ Y^2\ =\ (D\ y + E)^2 + D\ F - E^2,\quad\quad Y\ =\ 2ax + by + d $$
Therefore if we put $\rm\quad\ \ X\: =\: D\ y + E,\quad\ \ N\: =\: E^2 - D\ F\quad\ \ $ we obtain the Pell equation
$$\rm X^2 - D\ Y^2\ =\ N $$
Now you can apply standard techniques for solving Pell equations. They are a bit too complex to describe here. However, you can obtain complete step-by-step descriptions of the solution to any Pell equation using Dario Alpern's Quadratic two integer variable equation solver.  For some  recent optimizations of Lagrange's algorithm see this paper H. C. Williams et al. A new look at an old equation.
