Integer solutions to $\sqrt{ax^2+1}$ and the unusually large solutions While trying to simplify some triangle graphing I came across this equation  $\sqrt{ax^2+1}$  looking for integer solutions. Trivially $x=0$ is true for any $a$. However the non-trivial solutions have a nice recurrent relation.
For example, $\sqrt{5x^2+1}$ has the solutions $x=\{0,4,72,1292,23184\cdots\}$ defined by the recurrent relation $x_n = 19x_{n-1}-x_{n-2}$ with $x_0=0$ and $x_1=4$ 
In my triangle search I was at first looking for solutions to $\sqrt{(1+b^2)x^2+1}$. 
This actually had a nice recurrent relation. 
$x= \{0,2b,(4b^2+2)a_{n-1}-a_{n-2}\}$
That problem I have is what gives you the first nontrivial $x$ for a given $a$. When $a$ is of the form $b^2+1$ the relation is pretty nice. But consider the solutions to  $\sqrt{41x^2+1}$. The solution set is $x=\{0,320,1311360,5373952960\}$. Intuition had me consider large solutions when $a$ is prime but $a=47$ gives $x=\{0,7,672,64505\}$, but my python script can't find any solutions to $\sqrt{61x^2+1}$ under $10^7$
I suppose my question would be how to solve for the first two nontrivial solutions for any $a$ or any other insights or info on this equation. 
 A: The following procedure finds all integer solutions of $$ax^2+1=y^2$$ It works for any integer $a$ but I will use $a=41$ to illustrate it. Notice that if we divide by $x^2$ we get $\sqrt{a}\approx(y/x)$.
Calculate the continued fraction of $\sqrt{41}$ as $$\sqrt{41}=6+\frac{1}{2+\frac{1}{2+\frac{1}{12+\cdots}}}$$ This is just a sequence of fractions: $6$, $\frac{13}{2}$, $\frac{32}{5}$, $\frac{397}{62}$, $\ldots$ One of them will have numerator and denominator that solve the equation $41x^2+1=y^2$. (This is guaranteed from the theory of Pell equations). For $a=41$, the first one is the sixth fraction $2049/320$. As you point out, $x=320$, $y=2049$ is the smallest non-trivial solution.
For $a=61$ (which incidentally was proposed as a challenge by the Indian mathematician Bhaskara in the 12th century), the first fraction is the 22nd one $1766319049/226153980$ with integers of order $10^9$.
Once you find the smallest solution, you can obtain all other solutions by multiplying out $(y+x\sqrt{a})^n$ and simplifying. So, for $a=41$, the next solution is found from $$(2049+320\sqrt{41})^2=8396801 + 1311360\sqrt{41}$$ to be $x=1311360$, as your algorithm found out.
