TITLE: Does the Pell-like equation $X^2-dY^2=k$ have a simple recursion like $X^2-dY^2=1$?
QUESTION [11 upvotes]: If $d \ne 0$ is a non-square integer, and $(u,v)$ is an integer solution to the Pell equation
$$
  X^2 - dY^2 = 1,  \tag{$\star$}
$$
then each solution $(x_i,y_i)$ can be recursively calculated using the formulas
\begin{align}
x_{n+1} &= ux_n + dvy_n,  \\
y_{n+1} &= vx_n + uy_n\tag1
\end{align}
n.b. If $(u,v)$ is not the fundamental solution to ($\star$), the recursion still works, though you will instead get $(x_{n+m},y_{n+m})$ for some integer $m$ determined by which solution $(u,v)$ actually is. Thus you can always determine a larger solution to ($\star$), though not necessarily the next largest solution, using only a single solution $(x_n,y_n)$ and the recursion
\begin{align}
x_{n+1} &= x_n^2 + dy_n^2,  \\
y_{n+1} &= 2x_ny_n\tag2
\end{align}
QUESTION: Considering the equation
$$
  X^2 - dY^2 = k, \qquad k \ne 1,
$$
is there a similar simple recursion to determine $(x_{n+1},y_{n+1})$ knowing only $(x_n,y_n)$ [and possibly, though not necessarily, one other solution $(u,v)$]?
With $d=6$ and $k=3$, I tried applying the recursion for $X^2-6Y^2=1$ to the fundamental solution $(3,1)$ of the equation $X^2-6Y^2=3$, and ended up with a solution to the equation $X^2-6Y^2=9$. Since $9=3^2=k^2$, I feel like there might be just a small adjustment to be made to the recursion, to compensate for $k \ne 1$, but I haven't found it.

REPLY [2 votes]: I thought the idea for naming some "fundamental" solutions, from yesterday, was pretty good. I wrote a program to do that. I wanted to show what can happen if the target number is not squarefree. In the following output, $x^2 - 5 y^2 = 121,$ one out of three $(x,y)$ is just $11$ times a pair that solves $x^2 - 5 y^2 = 1.$
jagy@phobeusjunior:~$ ./Pell_Target_Fundamental

 x^2 - 5 y^2 = 121

x:  11  y:  0 ratio: 0  fundamental 
x:  21  y:  8 ratio: 0.380952  fundamental 
x:  29  y:  12 ratio: 0.413793  fundamental 
x:  99  y:  44 ratio: 0.444444
x:  349  y:  156 ratio: 0.446991
x:  501  y:  224 ratio: 0.447106
x:  1771  y:  792 ratio: 0.447205
x:  6261  y:  2800 ratio: 0.447213
x:  8989  y:  4020 ratio: 0.447213
x:  31779  y:  14212 ratio: 0.447214
x:  112349  y:  50244 ratio: 0.447214
x:  161301  y:  72136 ratio: 0.447214
x:  570251  y:  255024 ratio: 0.447214
x:  2016021  y:  901592 ratio: 0.447214
x:  2894429  y:  1294428 ratio: 0.447214
x:  10232739  y:  4576220 ratio: 0.447214


 x^2 - 5 y^2 = 121

jagy@phobeusjunior:~$

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Why not, here is $x^2 - 5 y^2 = -121.$
jagy@phobeusjunior:~$ ./Pell_Target_Fundamental

 x^2 - 5 y^2 = -121

x:  2  y:  5 ratio: 2.5  fundamental 
x:  22  y:  11 ratio: 0.5  fundamental 
x:  82  y:  37 ratio: 0.45122  fundamental 
x:  118  y:  53 ratio: 0.449153
x:  418  y:  187 ratio: 0.447368
x:  1478  y:  661 ratio: 0.447226
x:  2122  y:  949 ratio: 0.44722
x:  7502  y:  3355 ratio: 0.447214
x:  26522  y:  11861 ratio: 0.447214
x:  38078  y:  17029 ratio: 0.447214
x:  134618  y:  60203 ratio: 0.447214
x:  475918  y:  212837 ratio: 0.447214
x:  683282  y:  305573 ratio: 0.447214
x:  2415622  y:  1080299 ratio: 0.447214
x:  8540002  y:  3819205 ratio: 0.447214
x:  12260998  y:  5483285 ratio: 0.447214


 x^2 - 5 y^2 = -121

jagy@phobeusjunior:~$

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Here is a good pair, $x^2 - 11 y^2 = 14$ and then $x^2 - 11 y^2 = 350 = 14 \cdot 25.$
jagy@phobeusjunior:~$ ./Pell_Target_Fundamental

 x^2 - 11 y^2 = 14

Wed Mar 30 11:32:36 PDT 2016

x:  5  y:  1 ratio: 0.2  fundamental 
x:  17  y:  5 ratio: 0.294118  fundamental 
x:  83  y:  25 ratio: 0.301205
x:  335  y:  101 ratio: 0.301493
x:  1655  y:  499 ratio: 0.301511
x:  6683  y:  2015 ratio: 0.301511
x:  33017  y:  9955 ratio: 0.301511
x:  133325  y:  40199 ratio: 0.301511
x:  658685  y:  198601 ratio: 0.301511
x:  2659817  y:  801965 ratio: 0.301511
x:  13140683  y:  3962065 ratio: 0.301511

Wed Mar 30 11:32:56 PDT 2016

 x^2 - 11 y^2 = 14

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
jagy@phobeusjunior:~$ ./Pell_Target_Fundamental

 x^2 - 11 y^2 = 350

Wed Mar 30 11:29:54 PDT 2016

x:  19  y:  1 ratio: 0.0526316  fundamental 
x:  25  y:  5 ratio: 0.2  fundamental 
x:  41  y:  11 ratio: 0.268293  fundamental 
x:  47  y:  13 ratio: 0.276596  fundamental 
x:  85  y:  25 ratio: 0.294118  fundamental 
x:  157  y:  47 ratio: 0.299363  fundamental 
x:  223  y:  67 ratio: 0.300448
x:  415  y:  125 ratio: 0.301205
x:  773  y:  233 ratio: 0.301423
x:  899  y:  271 ratio: 0.301446
x:  1675  y:  505 ratio: 0.301493
x:  3121  y:  941 ratio: 0.301506
x:  4441  y:  1339 ratio: 0.301509
x:  8275  y:  2495 ratio: 0.301511
x:  15419  y:  4649 ratio: 0.301511
x:  17933  y:  5407 ratio: 0.301511
x:  33415  y:  10075 ratio: 0.301511
x:  62263  y:  18773 ratio: 0.301511
x:  88597  y:  26713 ratio: 0.301511
x:  165085  y:  49775 ratio: 0.301511
x:  307607  y:  92747 ratio: 0.301511
x:  357761  y:  107869 ratio: 0.301511
x:  666625  y:  200995 ratio: 0.301511
x:  1242139  y:  374519 ratio: 0.301511

Wed Mar 30 11:29:55 PDT 2016

 x^2 - 11 y^2 = 350

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=