Integer solutions of $3a^2 - 2a - 1 = n^2$

Solution 1:

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

Solution 2:

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.