Finding a solution to the generalised Pell's equation $x^2-31y^2=5$ I'm trying to find a solution to the generalised Pell's equation $x^2-31y^2=5$. So far I have found the fundamental solution $x=1520,y=273$ to the equation $x^2-31y^2=1$, obtained from calculating the convergents $p_n$ and $q_n$ in the continued fraction expansion of $\sqrt{31}$. It's also possible to find e.g. solutions to $x^2-31y^2=4$ just by dividing both sides of this equation by 4 and using the fundamental solution.
Since $5$ is prime, though, there doesn't seem to be an obvious way to generate a solution using e.g. Brahmagupta's identity by multiplying solutions with a factor of $5$ on the right hand side. How can you find a solution to this?

The same  continued fraction that told you    $1520^2 - 31 \cdot 273^2 = 1$  also tells you $6^2 - 31 \cdot 1^2 = 5$  and $657^2 - 31 \cdot 118^2 = 5$
I also have a program somewhere that  typesets the whole business below in Latex, for now here is the bald  version:
./Pell_Lubin  31

31

0.   5  : { sqrt(31) - 5} / 1  ;; 5 / 1 ::: 5^2  - 31 * 1^2  = -6
1.   1  : { sqrt(31) - 1} / 6  ;; 6 / 1 ::: 6^2  - 31 * 1^2  = 5
2.   1  : { sqrt(31) - 4} / 5  ;; 11 / 2 ::: 11^2  - 31 * 2^2  = -3
3.   3  : { sqrt(31) - 5} / 3  ;; 39 / 7 ::: 39^2  - 31 * 7^2  = 2
4.   5  : { sqrt(31) - 5} / 2  ;; 206 / 37 ::: 206^2  - 31 * 37^2  = -3
5.   3  : { sqrt(31) - 4} / 3  ;; 657 / 118 ::: 657^2  - 31 * 118^2  = 5
6.   1  : { sqrt(31) - 1} / 5  ;; 863 / 155 ::: 863^2  - 31 * 155^2  = -6
7.   1  : { sqrt(31) - 5} / 6  ;; 1520 / 273 ::: 1520^2  - 31 * 273^2  = 1
8.     10  :   { sqrt( 31 ) - 5 } / 1

