Solution (source code)

= Solution

Use the periodic <continued fraction> $\sqrt d=[a_0;\overline{a_1,\ldots,a_m}]$. A direct <matrix> argument avoids any assumption about the parity of the period. Let
$$
 T(a)=\begin{pmatrix}a&1\\1&0\end{pmatrix},\quad
 M=T(a_1)\cdots T(a_m),\quad B=T(a_0),\quad N=BMB^{-1}.
$$
Periodicity says that $M$ fixes $\theta_1$ as a <Möbius transformation>, while $B$ takes $\theta_1$ to $\sqrt d$. Thus $N=\begin{pmatrix}A&B_1\\C&D\end{pmatrix}$ has <integer> entries and fixes $\sqrt d$. Equating rational and irrational parts in $A\sqrt d+B_1=\sqrt d(C\sqrt d+D)$ gives $A=D,B_1=dC$. Consequently
$$
 A^2-dC^2=\det N=(-1)^m.
$$
The <eigenvalue> of $M$ on $(\theta_1,1)^T$ is its denominator $M_{21}\theta_1+M_{22}>1$; this uses $a_i\geq1$ and $\theta_1>1$, including the one-term period. The corresponding <eigenvalue> of $N$ is $A+C\sqrt d>1$. If the <algebraic norm> is $-1$, square this unit; otherwise keep it. In either case there is a unit $u=X+Y\sqrt d>1$ of <algebraic norm> $1$ with <integer> $X,Y$. Its powers have <integer> coefficients and <algebraic norm> $1$, and are distinct since $u^j$ strictly increases. Hence \b[Pell's equation has infinitely many <integer> solutions].