\documentclass[12pt,reqno]{article}

\usepackage[usenames]{color}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amscd}
\usepackage{graphicx}

\usepackage[colorlinks=true,
linkcolor=webgreen,
filecolor=webbrown,
citecolor=webgreen]{hyperref}

\definecolor{webgreen}{rgb}{0,.5,0}
\definecolor{webbrown}{rgb}{.6,0,0}

\usepackage{color}
\usepackage{fullpage}
\usepackage{float}

\usepackage{psfig}
\usepackage{graphics}
\usepackage{latexsym}
\usepackage{epsf}
\usepackage{breakurl}

\setlength{\textwidth}{6.5in}
\setlength{\oddsidemargin}{.1in}
\setlength{\evensidemargin}{.1in}
\setlength{\topmargin}{-.1in}
\setlength{\textheight}{8.4in}

\newcommand{\seqnum}[1]{\href{https://oeis.org/#1}{\rm \underline{#1}}}

\def\mystrut{\vrule height 15pt depth 5pt width 0pt}

\begin{document}

\begin{center}
\epsfxsize=4in
\leavevmode\epsffile{logo129.eps}
\end{center}

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}

\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{conjecture}[theorem]{Conjecture}

\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}

\begin{center}
\vskip 1cm{\Large\bf 
Patterns in Continued Fractions of Square Roots
}
\vskip 1cm
\normalsize
Amrik Singh Nimbran \\
B3-304, Palm Grove Heights\\
Ardee City \\
Sector 52, Gurugram\\
Haryana\\
India 122003 \\
\href{mailto:amrikn622@gmail.com}{\tt amrikn622@gmail.com} \\
\ \\
Paul Levrie \\
Faculty of Applied Engineering \\
University of Antwerp \\
Groenenborgerlaan 171 \\
2020 Antwerpen\\
and\\
Department of Computer Science \\
KU Leuven \\
P.O. Box 2402 \\
3001 Heverlee \\
Belgium \\
\href{mailto:paul.levrie@cs.kuleuven.be}{\tt paul.levrie@cs.kuleuven.be}
\end{center}

\vskip .2 in

\begin{abstract}
We examine the structure of the periodic continued fractions of square
roots of non-square positive integers given by an integer-valued quadratic
polynomial $Q(n)=(an+b)^2 +(gn+h)$. The aim is to identify repeated
blocks of partial quotients in the period. The quotients in the period
form a palindrome, and when the period length is even, the period has
a central term $a_n$. The paper focuses on periods with $a_n =a_0$ or
$a_n =a_0-1$, where $a_0$ is the initial partial quotient. For $a_n=a_0$ we give
an algorithm to obtain formulas involving repeated blocks comprising
three or more elements, not all equal.
\end{abstract}

\section{Introduction}
\label{Intro}

\subsection{Preliminaries}

Irrational square roots entered into mathematics with the Pythagorean theorem which led to the discovery of the irrationality of $\sqrt{2}$. About 400 BCE, rational approximations $\frac{a}{b}$ to $\sqrt{2}$ appeared in India and Greece. Bombelli (\emph{Algebra}, 1572) and Cataldi, who continued Bombelli's work, introduced continued fractions to approximate square roots.
For an irrational number $\alpha$, an expression of the form
\[
\alpha = a_0+\cfrac{1}{a_1+ \cfrac{1}{a_2+ \cfrac{1}{a_3 +\dotsb}}}
\]
with $a_i \in \mathbb{N}$ for $i \ge 0,$ is called a \emph{simple continued fraction} (scf) of $\alpha$. It is generally denoted by
a space-saving symbolism: $[a_0; a_1, a_2, a_3, \dots ]$. The integers $a_i$ are called \emph{partial quotients}. The rational number represented by the truncated continued fraction $[a_0; a_1, a_2, a_3, \dots, a_n]$ is called the $n$th \emph{convergent} ($c_n$) of $\alpha$. If we define the sequences $\lbrace p_k\rbrace$, $\lbrace q_k \rbrace$:
\begin{gather}
p_{-2} =0, \quad p_{-1} =1, \quad p_{k} = a_{k}~ p_{k-1} + p_{k-2} \; \text{for} \; k\ge 0, \nonumber \\
q_{-2} =1, \quad q_{-1} =0, \quad q_{k} = a_{k}~ q_{k-1} + q_{k-2} \; \text{for} \; k\ge 0, \nonumber
\end{gather}
then $\displaystyle [a_0; a_1, \dots, a_k]=\frac{p_k}{q_k}$.  Note that
$\begin{bmatrix}
p_{-1} & p_{-2}\\
q_{-1} & q_{-2}
\end{bmatrix}
 =
\begin{bmatrix}
1 & 0\\
0 & 1
\end{bmatrix}$
is the identity matrix.

If the quotients repeat from a point $r$ onward, i.e., $a_{m\ell+r+k} =a_{r+k}, \, m\in \mathbb{N}, \, 0\le k\le \ell$, with period length $\ell$, then the scf is said to be \emph{periodic} and is written as
\[
[a_0; a_1, a_2, \dots a_{r-1}, \overline{a_r, a_{r+1}, a_{r+2}, \dots, a_{r+\ell-1}}\,].
\]
If the scf repeats from the start, $[\, \overline{a_0, a_1, \dots, a_n}\, ]$, it is called \emph{purely} periodic.

Euler proved in 1737 that the value of every periodic scf is a quadratic irrational of the form $\frac{P +\sqrt{d}}{Q}$ with $P, Q \in \mathbb{Z}, ~ Q\ne 0$ and $d \in \mathbb{Z}^+$ not a perfect square. In 1770, Lagrange proved the converse of Euler's theorem that each quadratic irrational has a periodic scf expansion.

The \emph{continued fraction algorithm}, the algorithm for obtaining the scf of $\sqrt{d}$, is given in many books. See \cite[\S \ 8.4]{sierpinski}. The period of the scf of $\sqrt{d}$ is symmetrical and for period length $\ell (d)$ its form is
\[
\sqrt{d} = [a_0;~ \overline{a_1, a_2, a_3, \ldots, a_{\ell-3}, a_{\ell-2}, a_{\ell-1}, 2a_0}\,]
\]
with $a_1 =a_{\ell-1}, \, a_2=a_{\ell -2}, \dots$; $a_1, a_2, \dots, a_{\ell-1}$ form a palindrome that may or may not have a central term. When $\ell(d) =2n$, the period is symmetric around $a_n$ with $a_{n+1}=a_{n-1}, \, a_{n+2}=a_{n-2}$, and so on. If $\ell(d) =2n+1$, then $a_{n+1}=a_{n}, \, a_{n+2}=a_{n-1}$, and so on. $\ell (d)$ is odd if and only if $d=a^2+b^2, \, \gcd(a, b)=1$ \cite{rippon}. In the scf expansion of $\sqrt{d}$ with period length $\ell$, each partial quotient $a_k$ for $0 \le k < \ell$ satisfies $a_k < \sqrt{d}$ \cite[p.~245, 3(f)]{LeVeque} .

\subsection{Schinzel's criterion for bounded period length}

Schinzel \cite{schinzel} gave two theorems on the period length $\ell$ in the scf of $\sqrt{f(n)}$.

\noindent (A) Let $f(x)=\sum_{k=0}^p c_k~ x^{p-k}$ be an integer-valued polynomial with $c_0>0$. If (i) $p$ is odd or (ii) $p$ is even and $c_0$ is not a rational square, then $\displaystyle \overline{\lim}~ \ell \left(\sqrt{f(n)}\right) =\infty$.

\noindent (B) Let $f(n) = a^2 n^2 + bn +c, \; a, b, c \in \mathbb{Z}, \; a>0$. Then the inequality $\overline{\lim} ~ \ell \left(\sqrt{f(n)}\right) <\infty$ holds if and only if $\Delta \mid 4 \gcd(2a^2, b)^2$ where $\Delta= b^2 -4a^2c \ne 0$.

These two theorems together fully solved the problem of when $\ell \left(\sqrt{f(n)}\right)$ can be bounded independently of $n$ if $f(n)$ is an integer-valued quadratic polynomial \cite[pp.~134--135]{jacobwil}.

In \cite{poorten99}, van der Poorten and Williams obtained the scf of $\sqrt{A^2X^2 +2BX +C}$ in terms of $C$'s scf expansion. In this case Schinzel's condition becomes $B^2 - A^2C \mid 4 \gcd(A^2, B)^2$.

Cheng et al.\ \cite{chengd05, chengd12} considered the polynomial $D(X) =A^2X^2 +2BX +C$ that satisfies Schinzel's condition. They found that the scf of $\sqrt{D(X)}$ has the form
\[
[q_0(X);~ \overline{\mathcal{S}_0, q_1(X), \mathcal{S}_1, q_2(X), \dots, \mathcal{S}_{\kappa -1}, q_{\kappa}(X)} \,].
\]
Here the period comprises $\kappa$ segments, each consisting of a string $\mathcal{S}_i$ (an ordered set of natural numbers) followed by a linear function $ q_{i+1}(X)$. Using the notation $\overleftarrow{\mathcal{S}_j}$ for the reverse of $\mathcal{S}_j$, the symmetry of the period shows that $\mathcal{S}_{\kappa -1} = \overleftarrow{\mathcal{S}_0}$, $\mathcal{S}_{\kappa -2} = \overleftarrow{\mathcal{S}_1}$, and so on. $q_0(X) =a_0, \, q_{\kappa}(X) =2q_0(X)$. Furthermore, $q_{\kappa -1}(X) = q_1 (X)$, $q_{\kappa -2}(X) = q_2 (X)$, and so on.

We present two types of results (presumably new) obtained by us: (i) Scf expansions in individual formulas (numbered in the text) containing two parameters $m, n$; (ii) Theorems yielding polynomials that give \emph{predictable patterns each consisting of a single string or block repeated $k$ times}. Throughout the paper, $d$ is a non-square positive integer generated by $Q(n)=(an+b)^2 +(gn+h), \,  a, b, g, h \in \mathbb{Z}, \, (gn+h) < 2(an+b)$. This form of polynomial makes $a_0$ evident. Our technique involves `tweaking' the continued fraction of some smaller quadratic irrational whose quotients replicate themselves endlessly as a singleton, a pair, triple, etc. Tweaking inserts $a_0$ or $a_{0} -1$ 
in the middle of the pattern. We use the matrix method to validate our methodology.

\subsection{Two useful continued fraction expansions}\label{expansions}

Consider the equation $x^2 -(2m+1)x -1=0 \; \text{with roots} \; \frac{2m+1 \pm \sqrt{(2m+1)^2 +4}}{2}$.  The equation can be written as $x = (2m+1) +\frac{1}{x}$. Replacing $x$ by $(2m+1) +\frac{1}{x}$ in the RHS repeatedly leads to the scf of the positive root of the preceding equation:
\[
\frac{2m+1 +\sqrt{(2m+1)^2 +4}}{2} =2m+1+
\cfrac{1}{2m+1+
\cfrac{1}{2m+1+
\cfrac{1}{2m+1+
\dotsb
}}},
\]
which is denoted by $[2m+1; \overline{2m+1}\,]$. The convergents of this scf are given by
\[
 \frac{u_2}{u_1}, \, \frac{u_3}{u_2}, \ldots, \frac{u_{n+1}}{u_n}, \ldots.
\]
where $u_n$ ($n \in \mathbb{N}_0)$ has the closed form
\begin{equation}
u_n = \frac{\left(2m+1+\sqrt{(2m+1)^2+4}\right)^n -\left(2m+1 -\sqrt{(2m+1)^2+4} \right)^n}{2^n ~ \sqrt{(2m+1)^2+4}}. \label{power}
\end{equation}
Note that $u_{n}$ is even when $n=3r$, and odd when $n= 3r+1, \, 3r+2$.

The value $m=0$ yields a purely periodic scf for the \emph{golden ratio} whose convergents are ratios of the consecutive Fibonacci numbers $\displaystyle \frac{F_{n+1}}{F_n}$. The Fibonacci sequence $(F_n)_{n \geq 0}$ is given by the recurrence relation
\[
F_{n+1} = F_{n} + F_{n-1} \; \text{for} \; n\ge 1 \; \text{with}\; F_{0}=0, \; F_{1}=1.
\]
In this case \eqref{power} reduces to the well-known Euler-Binet closed formula for $F_n$.

It is obvious that $x^2 -2mx -k =0$ ($m\in \mathbb{N}, \, 1\le k \le m$) yields the quadratic irrational $m \pm \sqrt{m^2+k}$.

The equation: $\displaystyle x^2 -2x-1=0$, having roots $1 \pm \sqrt{2}$, can be rewritten as $x^2 = 2x +1$ or $x = 2 +\frac{1}{x}$.
Substituting $2 +\frac{1}{x}$ for $x$ repeatedly in the RHS yields the scf for the positive root:
\begin{equation*}
1 +\sqrt{2} = 2 +\cfrac{1}{2 +\cfrac{1}{2+\cfrac{1}{2+\dotsb}}} \Longrightarrow \sqrt{2} = 1 +\cfrac{1}{2 +\cfrac{1}{2+\cfrac{1}{2+\dotsb}}},
\end{equation*}
where the left scf is purely periodic unlike the right one. In
general, the scf of $\sqrt{d}$ is not purely periodic, while that of
$\lfloor\sqrt{d}\rfloor +\sqrt{d}$, where $\lfloor x \rfloor$ denotes
the greatest integer less than or equal to $x$, is purely periodic.

The convergents of $\sqrt{2} =[1; \overline{2}\,]$ are given by $\displaystyle \frac{p_{n}}{q_{n}} =\frac{2p_{n-1} +p_{n-2}}{2q_{n-1} +q_{n-2}}$ for $n\ge 1$ with $p_0=a_0=1, q_0=1, p_{-1}=1, q_{-1}=0$. So, for $n\ge 0$ we have
\[
\frac{1}{1}, \; \frac{3}{2}, \; \frac{7}{5}, \; \frac{17}{12}, \; \frac{41}{29}, \; \frac{99}{70}, \; \frac{239}{169}, \ldots .
\]
$\langle \frac{p_{2n-1} -1}{2}, ~\frac{p_{2n-1} +1}{2}, q_{2n-1} \rangle$ constitute Pythagorean triples. The numerators and denominators occur in \seqnum{A001333} and \seqnum{A000129} \cite{sloane}. Their closed forms are
\[
p_{k}= \frac{(1+\sqrt{2})^{k} +(1 -\sqrt{2})^{k}}{2}; \quad q_{k}= \frac{(1+\sqrt{2})^{k} -(1 -\sqrt{2})^{k}}{2\sqrt{2}}.
\]
From the closed forms, we can deduce the following relations:
\begin{subequations}\label{root2}
\begin{align}
& p_{k} = q_{k+1} - q_{k} = q_{k} + q_{k-1},  \label{root2a}\\
& 2 q_{k} = p_{k+1} - p_{k}= p_{k} + p_{k-1}. \label{root2b}
\end{align}
\end{subequations}

\section{Matrix method in continued fractions}

\subsection{Linear recurrences with constant coefficients}

The general form of a second-order linear recurrence with constant integer coefficients is $u_{n+1} =a\, u_{n} +b\, u_{n-1}$ with $a, b \in \mathbb{Z}\, (b\ne 0)$. Its characteristic equation is $x^2 -a x - b=0$. If $\alpha, \beta$ are its roots, then $\alpha +\beta =a, \; \alpha \cdot \beta =-b, \; \alpha -\beta = \sqrt{a^2 +4b}$. If $a^2+4b>0$, both roots are real with $\alpha \ne \beta$. In this case the general solution of the given recurrence is $u_n = \lambda \alpha^n +\mu \beta^n$ for $n = 0, 1, 2, \dots$ for arbitrary numbers $\lambda$ and $\mu$. If two initial values $u_0, \, u_1$ are given, these two numbers are uniquely determined by $\lambda +\mu =u_0; \;  \lambda\alpha + \mu\beta =u_1$  \cite[p.~199, Th.4.10, eq(4.5)]{niven}.

Lenstra and Shallit \cite{lenshallit} proved that the numerators and denominators of the convergents to an irrational number $\theta$ satisfy a (sometimes higher order) linear recurrence with constant coefficients if and only if $\theta$ is a quadratic irrational.


\subsection{Correspondence between matrices and convergents}
Given a sequence $a_0, a_1, a_2, \dots,$ we have
\begin{equation*}
 \begin{bmatrix}
a_0 & 1\\
1 & 0
\end{bmatrix}
 \begin{bmatrix}
a_1 & 1\\
1 & 0
\end{bmatrix}
\begin{bmatrix}
a_2 & 1\\
1 & 0
\end{bmatrix}
 \cdots
\begin{bmatrix}
a_n & 1\\
1 & 0
\end{bmatrix}
=
\begin{bmatrix}
p_{n} & p_{n-1}\\
q_{n} & q_{n-1}
 \end{bmatrix}
 \quad \text{for} \; n=0, 1, 2, \dots,
\end{equation*}
if and only if \; $\displaystyle \frac{p_n}{q_n} = [a_0; a_1, \dots, a_n]$ for $n=0, 1, 2, \dots $. This sets up a correspondence between certain products of $2\times 2$ matrices and continued fractions (\cite[p.~45]{allouche}, \cite[p.~142]{bombpoor}, \cite[p.~28]{borwein}, \cite{frame}, \cite[p.~244]{hurwitz}, \cite[p.~104]{poorten85}, \cite[p.~87]{poorten90}).

If $\alpha =[0; a_1, a_2, a_3, \dots]$ and hence $\displaystyle \frac{p_n}{q_n}=[0; a_1, a_2, \dots, a_n]$, then the convergents get inverted:
\[
M_n :=
\begin{bmatrix}
q_n & q_{n-1}\\
p_n & p_{n-1}
\end{bmatrix}
 =
\begin{bmatrix}
a_1 & 1\\
1 & 0
\end{bmatrix}
\begin{bmatrix}
a_2 & 1\\
1 & 0
\end{bmatrix}
 \cdots
\begin{bmatrix}
a_n & 1\\
1 & 0
\end{bmatrix}
\]
and the matrix $M_n$ is symmetrical if and only if $a_1, a_2, \dots, a_n$ is a palindrome and so $p_n=q_{n-1}$. See proof of Theorem 2.1 in \cite{adam}. Note that in this case we have for all $n\ge 1$ that
\[
\begin{bmatrix}
a_1 & 1\\
1 & 0
\end{bmatrix}
\begin{bmatrix}
a_2 & 1\\
1 & 0
\end{bmatrix}
\cdots
\begin{bmatrix}
a_n & 1\\
1 & 0
\end{bmatrix}
=
\begin{bmatrix}
q_n & q_{n-1}\\
q_{n-1} & q_{n-2}
\end{bmatrix} .
\]
Writing $\alpha =a_0 +\frac{1}{\alpha_1}, \;  \alpha_1 =a_1 +\frac{1}{\alpha_2}, \dots, \alpha_n =a_n +\frac{1}{\alpha_{n+1}} \, (\alpha_i >1)$, i.e., $\alpha =[a_0, a_1, \dots, a_n, \alpha_{n+1}]$ with $\alpha_{n+1}=[a_{n+1}, a_{n+2}, \dots]$, we have the following formula expressing $\alpha$ in terms of the \emph{complete quotient} $\alpha_{n+1}$ and two neighbouring convergents (\cite[p.~80, eq(14)]{davenport}, \cite[p.~45]{allouche}, \cite[p.~148, 2.6]{bombpoor}):
\begin{equation}
\alpha =\frac{\alpha_{n+1} p_n +p_{n-1}}{\alpha_{n+1} q_n +q_{n-1}} . \label{daven}
\end{equation}

Given a continued fraction for a number of the form $\sqrt{d}$ (with $d$ a non-square integer):
\[
\sqrt{d} = [a_0;~ \overline{a_1, a_2, a_3, \dots, a_{\ell-3}, a_{\ell-2}, a_{\ell-1}, 2a_0} \, ]
\]
with period length $\ell$, Rippon and Taylor \cite{rippon} deduced using \eqref{daven} the following lemma:
\begin{lemma}\label{lemma1}
If
\[
\begin{bmatrix}
A & B\\
B & C
\end{bmatrix}
=
\begin{bmatrix}
a_1 & 1\\
1 & 0
\end{bmatrix}
\begin{bmatrix}
a_2 & 1\\
1 & 0
\end{bmatrix}
\cdots
\begin{bmatrix}
a_{\ell-1} & 1\\
1 & 0
\end{bmatrix}
\]
then $\sqrt{d} =\sqrt{a^2 +b}$ with
\begin{equation}
a = a_0; \qquad b = \frac{2 a_0 B +C}{A} \label{rip}
\end{equation}
\end{lemma}

\begin{proof}
As in \cite{rippon}, if $\beta =a_0 +\alpha= [\overline{2a_0, a_1, a_2, \dots, a_{\ell -1}}\,],$ the convergents of $\beta$ are found from the columns of
\[\begin{bmatrix}
2a_0 & 1\\
1 & 0
\end{bmatrix}
\begin{bmatrix}
A & B\\
B & C
\end{bmatrix},
\]
so by periodicity and \eqref{daven},
\[
\beta = \displaystyle \frac{(2 a_0 A+ B) \beta + (2 a_0 B +C)}{A\beta +B}.
\]
Solving for $\beta$ leads to the desired result.
\end{proof}

\subsection{Power of the matrix associated with convergents of $\sqrt{2}$}
As Khovanskii \cite[p.~292, Ex.~20]{khovanskii} states, the matrix
\[\begin{bmatrix}
1 & 2\\
1 & 1
\end{bmatrix}
=
\begin{bmatrix}
p_0 & 2q_0\\
q_0 & p_0
\end{bmatrix}
\]
leads to $\sqrt{2}=[1; \overline{2}\,]$.

Using the values from Subsection \ref{expansions}, we deduce the relation
\begin{lemma}\label{lemma2}
\begin{equation*}
\begin{bmatrix}
1 & 2\\
1 & 1
\end{bmatrix}^{k}
=
\begin{bmatrix}
p_{k-1} & 2q_{k-1}\\
q_{k-1} & p_{k-1}
\end{bmatrix}.
\end{equation*}
\end{lemma}
\begin{proof}
We use induction. The statement is obviously true for $k=1$. Assume it to be true for $k=m$ so that
\[
\begin{bmatrix}
1 & 2\\
1 & 1
\end{bmatrix}^{m}
=
\begin{bmatrix}
p_{m-1} & 2q_{m-1}\\
q_{m-1} & p_{m-1}
\end{bmatrix}.
\]
Now
\[
\begin{bmatrix}
p_{m-1} & 2q_{m-1}\\
q_{m-1} & p_{m-1}
\end{bmatrix}
\cdot
\begin{bmatrix}
1 & 2\\
1 & 1
\end{bmatrix}
=
\begin{bmatrix}
p_{m-1} +2q_{m-1} & 2p_{m-1} +2q_{m-1}\\
p_{m-1} +q_{m-1} & p_{m-1} +2q_{m-1}
\end{bmatrix}
=
\begin{bmatrix}
p_{m} & 2q_{m}\\
q_{m} & p_{m}
\end{bmatrix},
\]
by using \eqref{root2a} and \eqref{root2b}. Thus we get
\[
\begin{bmatrix}
1 & 2\\
1 & 1
\end{bmatrix}^{m+1}
=
\begin{bmatrix}
p_{m} & 2q_{m}\\
q_{m} & p_{m}
\end{bmatrix}.
\]
The statement is thus true for $k=m+1$ also. Hence it is true for all $k$.
\end{proof}

Next, we record a useful formula:
\[
\begin{bmatrix}
2 & 1\\
1 & 0
\end{bmatrix}^k
=
\begin{bmatrix}
q_{k} & q_{k-1}\\
q_{k-1} & q_{k-2}
\end{bmatrix}
\]
provable by induction. We then have two relevant products, also provable by induction:
\begin{equation}
\begin{bmatrix}
1 & 1\\
1 & 0
\end{bmatrix}
\cdot
\begin{bmatrix}
2 & 1\\
1 & 0
\end{bmatrix}^k
=
\begin{bmatrix}
p_{k} & p_{k-1}\\
q_{k} & q_{k-1}
\end{bmatrix};
\quad
\begin{bmatrix}
2 & 1\\
1 & 0
\end{bmatrix}^k
\cdot
\begin{bmatrix}
1 & 1\\
1 & 0
\end{bmatrix}
=
\begin{bmatrix}
p_{k} & q_{k}\\
p_{k-1} & q_{k-1}
\end{bmatrix}.
\label{twomat}
\end{equation}


\subsection{Matrix associated with $\sqrt{3}$}

The convergents of $\sqrt{3} =[1; \overline{1, 2}\,]$ are $ \frac{1}{1}, \frac{2}{1}, \, \frac{5}{3}, \, \frac{7}{4}, \, \frac{19}{11}, \, \frac{26}{15}, \, \frac{71}{41}, \, \frac{97}{56}, \, \frac{265}{153}, \dots,$ whose numerators occur in
\seqnum{A002531} and denominators in \seqnum{A002530} and have these closed forms:
\begin{align*}
& p_{2n-1} = \frac{(1+\sqrt{3})^{2n} +(1-\sqrt{3})^{2n} }{2^{n+1}}; \; q_{2n-1} = \frac{(1+\sqrt{3})^{2n} -(1-\sqrt{3})^{2n} }{2^{n+1}\sqrt{3}}, \\
& p_{2n} = \frac{(1+\sqrt{3})^{2n+1} +(1-\sqrt{3})^{2n+1} }{2^{n+1}}; \; q_{2n} = \frac{(1+\sqrt{3})^{2n+1} -(1-\sqrt{3})^{2n+1} }{2^{n+1}\sqrt{3}}.
\end{align*}
From the closed forms, we deduce the following relations:
\begin{align}
& p_{2n-1} =q_{2n} -q_{2n-1}; \; p_{2n+1} =q_{2n} +q_{2n+1};  \label{3a}\\
& 3q_{2n} +2q_{2n-1} =q_{2n+2}; \; 2q_{2n-1} +q_{2n-2} =q_{2n}. \label{3b}
\end{align}

By using the relations \eqref{3a} and \eqref{3b}, we can prove (for $k\in \mathbb{N}$) by induction:
\begin{lemma}\label{lemma3}
\begin{equation}
\begin{bmatrix}
3 & 2\\
1 & 1
\end{bmatrix}^k
=
\begin{bmatrix}
q_{2k} & 2q_{2k-1}\\
q_{2k-1} & q_{2k-2}
\end{bmatrix}.
\label{eq:l2}
\end{equation}
\end{lemma}

\subsection{Power of a general matrix}\label{genmat}
We introduce a matrix to be used later.
\begin{lemma}\label{lemma4}
\begin{equation*}
\begin{bmatrix}
2m+1 & 1 \\
1 & 0
\end{bmatrix}^{n}
=
\begin{bmatrix}
u_{n+1} & u_{n} \\
u_{n} & u_{n-1}
\end{bmatrix},
\end{equation*}
where $u_n$ satisfies the recurrence relation
\begin{equation*}
u_{n+1}=(2m+1)~ u_{n} +u_{n-1} \; \text{with} \; u_1=1, \, u_{0} =0. \label{recurrence}
\end{equation*}
\end{lemma}

\begin{proof}
The statement is obviously true for $n = 1$ in view of \eqref{recurrence}.  Assume the statement to be true for $n=r$ so that
\[
\begin{bmatrix}
2m+1 & 1  \\
1 & 0
\end{bmatrix}^r
=
\begin{bmatrix}
u_{r+1} & u_{r}  \\
u_{r} & u_{r-1}
\end{bmatrix}.
\]
Then
\begin{align*}
\begin{bmatrix}
2m+1 & 1  \\
1 & 0
\end{bmatrix}^{r+1}
&=
\begin{bmatrix}
u_{r+1} & u_{r}  \\
u_{r} & u_{r-1}
\end{bmatrix}
\begin{bmatrix}
2m+1 & 1  \\
1 & 0
\end{bmatrix}\\
& =
\begin{bmatrix}
(2m+1) u_{r+1} +u_{r} &  u_{r+1}  \\
(2m+1) u_{r} +u_{r-1} &  u_{r}
\end{bmatrix} =
\begin{bmatrix}
u_{r+2} & u_{r+1}  \\
u_{r+1} & u_{r}
\end{bmatrix}
\end{align*}
by using \eqref{recurrence}. So the statement is true for $n=r+1$ also. Hence it is true for all $n$.
\end{proof}


\section{Formulas without central term or central term $< a_0$}

\subsection{Selected formulas without central term}

\subsubsection{Formulas with $\ell (d)=2$}

These two are the only expansions ($m \ge 1$) of length 2 \cite[Th.~3]{arnold}.
\begin{equation}
\sqrt{(mn)^2 +n}=[mn; \overline{2m, 2mn}\,], n>1; \; \sqrt{(mn)^2 +2n}=[mn; \overline{m, 2mn}\, ], n \ge 1. \label{amrik1}
\end{equation}

\subsubsection{Formulas with $\ell (d)=3$}
This formula of Perron \cite[p.~100]{perron} gives the only possible scf:
\[
\sqrt{((4m^2+1) n +m )^2 +4mn +1}=[(4m^2+1)n +m; \overline{2m, 2m, 2((4m^2+1) n +m)}\,].
\]

\subsubsection{Formula with $\ell (d)=5$}

This formula will be used in a later section:
\begin{equation}
\sqrt{(2n+1)^2 +4} =[2n+1; ~ \overline{n, 1, 1, n, 4n+2}\,]. \label{amrik5a}
\end{equation}
\begin{proof}
Writing $\sqrt{d} = \sqrt{a^2 +b} = a+y$, and $y = [0; \frac{a-1}{2}, 1, 1,  \frac{a-1}{2}, 2a+y]$ gives the equation $y^2 +2ay -4=0$ with roots $y=-a \pm \sqrt{a^2 +4}$. For $\frac{a-1}{2}$ to be integer, $a$ must be $2n+1$.
\end{proof}

\subsection{Formulas with central term $< a_0 -1$}

\subsubsection{Formula with $\ell (d)=6$}
We can easily establish the following formula ($n \in \mathbb{N}$) by the continued fraction algorithm:
\begin{equation*}
\sqrt{(2n+2)^2 +(4n+1)} =[2n+2; ~ \overline{1, n, 2, n, 1, 2(2n+2)}\,].
\end{equation*}

\subsubsection{Formula with $\ell (d)=8$}
This formula ($n \in \mathbb{N}$) can be proved by the continued fraction algorithm:
\begin{equation*}
\sqrt{(4n+5)^2 +(8n+3)} =[4n+5; ~ \overline{1, n, 2, 2n+2, 2, n, 1, 2(4n+5)}\,].
\end{equation*}

\subsubsection{Formula with $\ell (d)=12$}
This formula ($n=0, 1, 2, \dots$) can be proved by the continued fraction algorithm:
\begin{equation*}
\sqrt{(209n+48)^2 +(264n+61)} =[209n+48; \overline{1, 1, 1, 2, 2, 38n+8, 2, 2, 1, 1, 1, 2(209n+48)}\,].
\end{equation*}

\subsection{Formulas with central term $a_{0} -1$}

\subsubsection{Formula with $\ell (d)=10$}

We discovered this formula for scf expansions for $m, n \in \mathbb{N}$:
\begin{align*}
& \sqrt{((8m^2 +1)n +2m(4m-1))^2 +((4m-1)^2 +1)n +(4m -1)^2 -2(2m -1)} = \\
&\hspace{1cm} [(8m^2 +1)n +2m(4m-1); \overline{1, 2m-1, 2m+1, 1, (8m^2 +1)n +2m(4m-1)-1,}  \\
& \hspace{1cm}\overline{ 1, 2m+1, 2m-1, 1, 2((8m^2 +1)n +2m(4m-1))}\,].
\end{align*}
The coefficients occur in \seqnum{A081585} and \seqnum{A080856}. The formula can be proved by the continued fraction algorithm.

\subsubsection{Formula with $\ell (d)=12$}
We further discovered this formula for $m=2, 3, 4, \dots$, and $n \in \mathbb{N}$:
\begin{align*}
& \sqrt{((2m^2 +4m +1)n +m)^2 + 2(2m^2 +2m -1)n +(2m -1)} =  \\
& \hspace{1cm}[(2m^2 +4m +1)n +m; \overline{1, m-1, 1, 2m, 1, (2m^2 +4m +1)n +m-1,}   \\
&  \hspace{1cm} \overline{1, 2m, 1, m-1, 1 2((2m^2 +4m +1)n +m)}\,].
\end{align*}
The coefficients occur in \seqnum{A056220} and \seqnum{A142463}. It can be proved similarly.

Cheng et al.\ give Example 3.1 in \cite{chengd05} with $D(X) =119^2 X^2 +2(2205)X + 343$ where $7^2$ divides $A, B, C$. As $\Delta = B^2 -A^2 C =2\cdot7^4$, Schinzel's condition is satisfied. For each $r$ in $X\equiv r \pmod 7$ with $r=0, 1, 2, \dots, 6$, the structure of the period is similar. Period length being even for every $r$, every period has the central or middle term. It is expedient to rewrite $D(X)$ as $(119X+18)^2 + (126X+19)$ to make $a_0$ evident. We find that $a_m =a_0 -1$ only when $r=0, 1, 3, 4$. So we get these four expansions (of lengths 28, 32, 76, 80) valid for $n\in \mathbb{N}_0$:\\
\begin{align*}
& \sqrt{(833n +375)^2 + 882n +397} = [833n +375; \overline{1, 1, 8, 17n+7, 1, 1, 4, 1, 10, 34n +15, 4, 3, 1,} \\
& \hspace{1cm}  \overline {833n +374, 1, 3, 4, 34n+15, 10, 1, 4, 1, 1, 17n+7, 8, 1, 1, 2(833n +375)}\,].
\end{align*}
\begin{align*}
&  \sqrt{(833n +137)^2 + 882n +145} = [833 n +137; \overline{1, 1, 8, 17n+2, 1, 2, 4, 1, 1, 1, 2, 34n +5, 4, 3, 1,}  \\
& \hspace{1cm} \overline { 833n +136, 1, 3, 4, 34n+5, 2, 1, 1, 1, 4, 2, 1, 17n+2, 8, 1, 1, 2(833 n +137)}\,].
\end{align*}
\begin{align*}
& \sqrt{(833n +851)^2 + 882n +901} = [833n +851; \overline{1, 1, 8, 17n+17, 3, 1, 5, 4, 1, 34n+33,} \\
& \hspace{0.5cm} \overline{1, 18, 1, 4, 1, 17n+16, 1, 1, 4, 1, 10, 34n+34, 1, 1, 1, 38, 1, 17n +16, 2, 2, 11, 1, 1, 34n+34,}  \\
& \hspace{0.5cm} \overline{4, 3, 1, 833n +850, 1, 3, 4, 34n+34, 1, 1, 11, 2, 2, 17n+16, 1, 38, 1, 1, 1, 34n+34,} \\
& \hspace{0.5cm} \overline{10, 1, 4, 1, 1, 17n+16, 1, 4, 1, 18, 1, 34n+33, 1, 4, 5, 1, 3, 17n+17, 8, 1, 1, 2(833n +851)}\,].
\end{align*}
\begin{align*}
& \sqrt{(833n +494)^2 + 882n +523} = [833n +494; \overline{1, 1, 8, 17n+9, 1, 38, 1, 1, 1, 34n+19,}\\
& \hspace{0.2cm} \overline{1, 1, 11, 2, 2, 17n+9, 1, 2, 4, 1, 1, 1, 2, 34n+19, 1, 4, 5, 1, 3, 17n+9, 1, 4, 1,18, 1, 34n+19,}\\
& \hspace{0.2cm} \overline{4, 3, 1, 833n +493, 1, 3, 4, 34n+19, 1, 18, 1, 4, 1, 17n+9, 3, 1, 5, 4, 1, 34n+19,}  \\
& \hspace{0.2cm} \overline{2, 1, 1, 1, 4, 2, 1, 17n+9, 2, 2, 11, 1, 1, 34n+19, 1, 1, 1, 38, 1, 17n+9, 8, 1, 1, 2(833n +494)}\,].
\end{align*}
What we are interested in are expansions involving a \emph{single string} so that we can find expansions wherein the same string repeats $k$ times. For example, we found these three expansions of length 28 each of which can be proved by the continued fraction algorithm:
\begin{align*}
& \sqrt{(23689 n + 26)^2 +(38574 n + 43)} =[23689 n + 26; \notag \\
& \hspace{0.2cm}\overline{1, 4, 2, 1, 1, 1, 1, 1, 4, 3, 1, 9, 1, 23689 n + 25, 1, 9, 1, 3, 4, 1, 1, 1, 1, 1, 2, 4, 1, 2(23689 n + 26)}\,],\\
& \sqrt{(203009 n + 24)^2 + (192646 n + 23)} =[203009 n + 24; \notag \\
& \hspace{0.2cm}\overline{2, 9, 3, 2, 1, 1, 3, 1, 6, 4, 1, 2, 1, 203009 n + 23, 1, 2, 1, 4, 6, 1, 3, 1, 1, 2, 3, 9, 2,  2(203009 n + 24)}\,],\\
& \sqrt{(326471 n + 22)^2 + (44450 n + 3)} =[326471 n + 22; \notag \\
& \hspace{0.2cm}\overline{14, 1, 2, 4, 1, 1, 3, 2, 5, 1, 6, 1, 1, 326471 n + 21, 1, 1, 6, 1, 5, 2, 3, 1, 1, 4, 2, 1, 14, 2(326471 n + 22)}\,].
\end{align*}
The next scf having the period length of 30 can be proved similarly:
\begin{align*}
& \sqrt {(3690313 n + 33)^2 + (558498 n + 5)} = [3690313 n + 33; \overline {13, 4, 1, 1, 1, 5, 2, 1, 2,} \notag\\
& \hspace{1cm} \overline {3, 9, 6, 1, 1, 3690313 n + 32, 1, 1, 6, 9, 3, 2, 1, 2, 5, 1, 1, 1, 4, 13, 2 (3690313 n + 33)} \,].
\end{align*}

\subsubsection{Formula with repeated $2$'s}

Perron gives this formula \cite[p.~114]{perron} with $\ell (d)=6$:
\begin{equation*}
\sqrt{(3n +1)^2 +(2n +1)} =[3n+1; ~ \overline{2, 1, 3n, 1, 2, 6n+2}\,].
\end{equation*}
Kraitchik \cite[p.~47]{kraitchik} gives this formula with $\ell (d)=8$:
\begin{equation*}
\sqrt{(7n +1)^2 +(6n +1)} =[7n+1; ~ \overline{2, 2, 1, 7n, 1, 2, 2, 14n+2}\,].
\end{equation*}
These formulas are special cases of the following theorem:
\begin{theorem}\label{thm1}
Let $p_{k}$ be the numerator in the $k$-th convergent of $\sqrt{2}$. Then for $k=1, 2, \dots$
\begin{equation*}
\sqrt{(p_{k}~ n +1)^2 +(2 p_{k-1} ~n +1)} = [p_{k} n +1;
\overline{\underbrace{2,2,\ldots,2}_k, 1, p_{k} n, 1, \underbrace{2,2,\ldots,2}_k,  2(p_{k} n +1)}\ ].
\end{equation*}
\end{theorem}

\begin{proof}
Let $\sqrt{d}:=a+y=[a; \overline {2, 1, a-1, 1, 2, 2a}\,]$. Then
\[
y = [0; 2, 1, a-1, 1, 2,y+2a],
\]
which leads to the equation $3 y^2 + 6a y - (2a+1) =0$.
Solving the quadratic equation, we get the positive root $y = -a +\sqrt{a^2 +\frac{2a+1}{3}}$. This implies that $b=\frac{2a+1}{3}$, which must be an integer if $d$ is to be an integer. The solution $a=3n+1$ gives $b=2n+1$.

When $\sqrt{d} =[a; \overline {2, 2, 1, a-1, 1, 2, 2, 2a}\,]$, the same procedure gives the equation $7y^2 +14ay -(6a+1) =0$ whose positive root yields $b=\frac{6a+1}{7}$ and for $d$ to be an integer we have $a=7n+1$ and $b=6n+1$.

With $\sqrt{d} =[a; \overline {2, 2, 2, 1, a-1, 1, 2, 2, 2, 2a}\,]$ the procedure gives the equation $17y^2 +34ay -(14a+3) =0$ whose positive root yields $b=\frac{14a+3}{17}$ and for $d$ to be an integer we have $a=17n+1$ and $b=14n+1$.

And if 2 is repeated $k$ times in the period, we get the equation $p_{k+1} y^2 +2p_{k+1} ay -(2p_{k} a+ p_{k-1}) =0$ whose positive root yields $b=\frac{2p_{k}a+ p_{k-1}}{p_{k+1}}$ and for $d$ to be an integer we have $a = p_{k+1}n+1$ and $b= 2p_{k}n+1$ where $p_k$ is the numerator of $c_k$ of $\sqrt{2}$. To apply \eqref{rip} to the general case, we note that in this case
\begin{equation*}
\begin{bmatrix}
A & B \\
B & C
\end{bmatrix}
=
\begin{bmatrix}
2 & 1 \\
1 & 0
\end{bmatrix}^{k-1}
\cdot
\begin{bmatrix}
1 & 1 \\
1 & 0
\end{bmatrix}
\cdot
\begin{bmatrix}
p_k n & 1 \\
1 & 0
\end{bmatrix}
\cdot
\begin{bmatrix}
1 & 1 \\
1 & 0
\end{bmatrix}
\cdot
\begin{bmatrix}
2 & 1 \\
1 & 0
\end{bmatrix}^{k-1}.
\end{equation*}
Using \eqref{twomat}, we get
\[
\begin{bmatrix}
2 & 1 \\
1 & 0
\end{bmatrix}^{k-1}
\cdot
\begin{bmatrix}
1 & 1 \\
1 & 0
\end{bmatrix}
 =
\begin{bmatrix}
p_k & q_k \\
p_{k-1} & q_{k-1}
\end{bmatrix}
\]
we can rewrite this matrix as follows:
\begin{align*}
& \begin{bmatrix}
A & B \\
B & C
\end{bmatrix}=\begin{bmatrix}
p_{k} & q_{k} \\
p_{k-1} & q_{k-1}
\end{bmatrix}
 \cdot
\begin{bmatrix}
p_k n & 1 \\
1 & 0
\end{bmatrix}
 \cdot
\begin{bmatrix}
p_k & p_{k-1} \\
q_k & q_{k-1}
\end{bmatrix} \\
& = \begin{bmatrix}
p_{k}^3 n+2p_k~q_k & p_{k}^2~ p_{k-1} n +p_k~q_{k-1}+p_{k-1}~q_k \\
p_{k}^2~ p_{k-1} n +p_k~q_{k-1}+p_{k-1}~q_k & p_k~ p_{k-1}^2 n + 2p_{k-1}~q_{k-1}
\end{bmatrix}.
\end{align*}
We now use Lemma \ref{lemma1}.

Since in Theorem \ref{thm1} $a_0 = p_k n +1$, we have that $a= a_0 = p_k n +1$ and
\begin{align*}
b & = \frac{2 a_0 B+C}{A} \\
& = \frac{2 (p_k n +1) (p_{k}^2~ p_{k-1} n +p_k~q_{k-1}+p_{k-1}~q_k) + p_k ~p_{k-1}^2 n + 2p_{k-1}~q_{k-1}}{p_{k}^3 n+2p_k~q_k} .
\end{align*}
What we have to show is that $b=2p_{k-1} n + 1$, or that
\begin{align*}
& 2 (p_k n +1) (p_{k}^2~ p_{k-1} n +p_k~q_{k-1}+p_{k-1}~q_k) + p_k~ p_{k-1}^2 n + 2p_{k-1}~q_{k-1}\\&  = (2p_{k-1} n + 1)(p_{k}^3 n+2p_k~q_k).
\end{align*}
After canceling equal terms involving $n^2$ on both sides, and subtracting $2p_{k} ~p_{k-1}~q_{k} n$ from both sides, we are left with \[
\text{LHS} = \left(2 p^2_{k}~q_{k-1} + 2 p^2_{k}~p_{k-1} + p_{k}~ p^2_{k-1}\right)n + 2 p_{k}~q_{k-1} +2 p_{k-1}~q_{k} +2 p_{k-1}~q_{k-1}.
\]
\[
{\rm RHS} = \left(p^3_{k} + 2 p_{k}~ p_{k-1}~q_{k}\right) n + 2 p_{k}~q_{k}.
\]
Using the relation $p_{k-1} +q_{k-1} =q_k$, as deduced in \eqref{root2b}, we have
\[
\text{LHS} = \left(2 p^2_{k}~q_{k} + p_{k}~ p^2_{k-1}\right)n + 2 (p_{k}~q_{k-1} + p_{k-1}~q_{k} + p_{k-1}~q_{k-1}).
\]
Comparing LHS and RHS, we have to show that
\begin{equation}
2 p_{k}~q_{k} +  p^2_{k-1} = p^2_{k} + 2  p_{k-1}~q_{k} \mbox{ and }
p_{k}~q_{k-1} + p_{k-1} (q_{k} + q_{k-1}) =  p_{k}~q_{k}. \label{toprove}
\end{equation}
The equation at the left is a consequence of \eqref{root2b}: we need to show that
\[
2 q_{k} = p_{k} + p_{k-1} \Rightarrow 2 q_{k} (p_{k} - p_{k-1}) = p^2_{k} - p^2_{k-1} \Rightarrow 2 p_{k}~q_{k} +p^2_{k-1} = p^2_{k} + 2 p_{k-1}~q_{k} .
\]
Using the relation \eqref{root2a}: $p_k = q_k + q_{k-1}$, the equation at the right in \eqref{toprove} reduces to
\[
p_{k}~q_{k-1} + p_{k-1}~ p_k =  p_{k}~q_{k},
\]
which follows on using the relation $p_{k-1} +q_{k-1} =q_k$ again.
\end{proof}

Our investigation with various blocks other than the singleton (2), which becomes (2, 2), (2, 2, 2), etc., suggests the conjecture that \emph{no other string can repeat in the period with central term $=a_0-1$.}

\section{Formulas with central term $a_0$}


\subsection{Formulas with $\ell (d)=6$}

For any fixed $m \in \mathbb{N}$ and $n=1, 2, 3, \dots,$ we have
\begin{align*}
& \sqrt{((2m^2 +1)n +m)^2 + 2(2mn + 1)} = [(2m+1)n +m; \notag \\
& \hspace{1cm} \overline{ m, 2m, (2m^2 +1)n +m,  2m, m, 2((2m+1)n +m) } \,].
\end{align*}
The formula can be proved by means of the continued fraction algorithm.

\subsection{Formulas with $\ell (d)=8$}

We find the following result in Kraitchik's book \cite[p.~47]{kraitchik}:
\[
\sqrt{(7n+5)^2 +2(4n+3)} =[7n+5; ~ \overline{1, 1, 3, 7n+5, 3, 1, 1, 14n+10}\,], \, n \in \mathbb{N}_0.
\]
It is a special case $(m=2)$ of the following \emph{general formula} for any fixed $m \in \mathbb{N}\setminus \lbrace 1 \rbrace$:
\begin{align*}
& \sqrt{ ( (2m^2 -1)n +2m^2 -m-1)^2 +2(2mn +2m -1)} = [(2m^2 -1)n +2m^2 -m-1; \notag \\
& \hspace{1cm}  \overline{  m-1, 1, 2m-1, (2m^2 -1)n +2m^2 -m-1, 2m-1,}  \notag \\
& \hspace{1cm}  \overline {1, m-1, 2((2m^2 -1)n +2m^2 -m-1)}\, ],
\end{align*}
which can be proved by using the continued fraction algorithm. The sequences appearing here occur in \seqnum{A056220} and \seqnum{A014106}.

\subsection{Formula with $\ell (d)=10$}
We have this pair of expansions valid for  $n= 1, 2, \dots$,
\begin{align*}
\sqrt{(9n+3)^2 +18} & =[9n+3; ~ \overline{n, 2, 1, 2n, 9n+3, 2n, 1, 2, n, 2(9n+3)}\,], \\
\sqrt{(9n+6)^2 +18} & =[9n+6; ~ \overline{n, 1, 2, 2n+1, 9n+6, 2n+1, 2, 1, n, 2(9n+6)}\,].
\end{align*}
Both can be proved easily by the continued fraction algorithm.

\section{Formulas with replicating pair $( m, \, 2m)$}

\subsection{Formula with repeated pair $( 1, 2 )$}

\begin{theorem}\label{thm2}
Let $q_{k}$ denote the denominator of the convergent to $\sqrt{3}$. Then for $k\in \mathbb{N}$
\begin{align*}
& \sqrt{(q_{2k}~ n +1)^2 +2(2q_{2k-1} ~n +1)} = [q_{2k}~ n +1;  \\
&  \hspace{1cm} \overline{\underbrace{1,2, 1,2,\ldots,1,2}_k, (q_{2k}~ n +1), \underbrace{2,1, 2,1, \ldots, 2,1}_k, 2(q_{2k}~ n +1)}\ ].
\end{align*}
\end{theorem}

\begin{proof}

As noted in \cite{lenshallit}, we have $q_{n+4} =4q_{n+2} -q_{n}$ for all $n\ge0$.

The sequences defined above give $\displaystyle \frac{q_{2k}}{q_{2k-1}}$ for $k=1, 2, 3, \dots$
\[
\frac{3}{1}, \, \frac{11}{4}, \, \frac{41}{15}, \, \frac{153}{56}, \, \frac{571}{209}, \ldots .
\]
From Lemma \ref{lemma2} we have
\[
\begin{bmatrix}
3 & 2\\
1 & 1
\end{bmatrix}^k
=
\begin{bmatrix}
q_{2k} & 2q_{2k-1}\\
q_{2k-1} & q_{2k-2}
\end{bmatrix}.
\]
Hence,
\[
\begin{bmatrix}
3 & 2\\
1 & 1
\end{bmatrix}^2
=\begin{bmatrix}
11 & 8\\
4 & 3
\end{bmatrix};
\quad
\begin{bmatrix}
3 & 2\\
1 & 1
\end{bmatrix}^3
=\begin{bmatrix}
41 & 30\\
15 & 11
\end{bmatrix};
\quad
\begin{bmatrix}
3 & 2\\
1 & 1
\end{bmatrix}^4
=\begin{bmatrix}
153 & 112\\
56 & 41
\end{bmatrix}.
\]
Applying the same procedure as in the proof of Theorem \ref{thm1}, we have $\sqrt{d} =\sqrt{a^2+b} =[a; \overline {1, 2, a, 2, 1, 2a}\,]$ and
\[
y = [0; 1, 2, a, 2, 1, y+2a],
\]
which after some long calculation leads to the
equation $3 y^2 + 6a y - (4a+2) =0$. Solving the quadratic equation, we get as positive root $y = -a +\sqrt{a^2 +\frac{4a+2}{3}}$. For $d$ to be an integer we have to take $a=3n+1$ giving $b=4n+2$.

When $\sqrt{d} =[a; \overline {1, 2, 1, 2, a, 2, 1, 2, 1, 2a}\,]$, the same procedure gives the equation $11y^2 +22ay -(16a+6) =0$ whose positive root yields $b=\frac{16a+6}{11}$ and for $d$ to be an integer we take $a=11n+1$ and $b=16n+2$.

With $\sqrt{d} =[a; \overline {1, 2, 1, 2, 1, 2, a, 2, 1, 2, 1, 2, 1, 2a}\,]$, the procedure gives the equation $41y^2 +82ay -(60a+22) =0$ and hence for $d$ to be an integer we take $a=41n+1$ and $b=60n+2$.

And for $k$ times the pairs $(1, 2)$ and $(2, 1)$, the equation obtained is $q_{2k}~y^2 +2q_{2k}a~y -2(2q_{2k-1}a +q_{2k-2}) =0$, which gives $a=q_{2k}n +1, \; b=2(2q_{2k-1}n +1)$.

\end{proof}

The first three formulas follow.
\begin{align*}
\sqrt{(3n+1)^2 +2(2n+1)} &=[3n+1; ~ \overline{1, 2, 3n+1, 2, 1, 2(3n+1)}\,].\\
\sqrt{(11n+1)^2 +2(8n+1)} &=[11n+1; ~ \overline{1, 2, 1, 2, 11n+1, 2, 1, 2, 1, 2(11n+1)}\,].\\
\sqrt{(41n+1)^2 +2 (30n+1)} &=[41n+1; \overline{1, 2, 1, 2, 1, 2, 41n+1, 2, 1, 2, 1, 2, 1, 2(41n+1)}\,].
\end{align*}

\subsection{Generalization of Theorem \ref{thm2}}
Let $\sqrt{m^2 +2} =[m; \overline {m, 2m}\,]$, and let $q_{2k}, \, q_{2k-1}$ be the denominators of its convergents. We have $q_{2k+1} =mq_{2k} +q_{2k-1}$ and the recurrence with gap 2 $x_{i+2}=2(m^2+1) x_{i} -x_{i-2}$, which gives
\begin{align*}
q_{2k+1} & = 2(m^2+1) q_{2k-1} -q_{2k-3}, \; q_1=1, \; q_{-1} =1, \\
q_{2k+2} & = 2(m^2+1) q_{2k} -q_{2k-2}, \; q_0=1, \; q_{2} =m.
\end{align*}
We then have the following generalization of Theorem \ref{thm2}:
\begin{theorem}\label{thm3}
Let the numbers be as defined above. Then for $k\in \mathbb{N}$
we have
\begin{align*}
& \sqrt{(q_{2k}~ n +m)^2 +2(2q_{2k-1} ~n +1)} = \left[\right.q_{2k}~ n +m; \overline{\underbrace{m,2m, m,2m,\ldots, m,2m}_k }, \\
&  \hspace{1cm} \overline{(q_{2k}~ n +m), \underbrace{2m,m, 2m,m, \ldots, 2m,m}_k, 2(q_{2k}~ n +m)} \left.\right].
\end{align*}
\end{theorem}

\begin{proof}
The proof of the general case is similar to the proof of Theorem \ref{thm1}.
We prove the case $m=1$:
\[
\left(
\begin{bmatrix}
1 & 1 \\
1 & 0
\end{bmatrix}
\cdot
\begin{bmatrix}
2 & 1 \\
1 & 0
\end{bmatrix}\right)^k
\cdot
\begin{bmatrix}
q_{2k} n +1 & 1 \\
1 & 0
\end{bmatrix}
\cdot \left(
\begin{bmatrix}
2 & 1 \\
1 & 0
\end{bmatrix}
\cdot
\begin{bmatrix}
1 & 1 \\
1 & 0
\end{bmatrix}\right)^k
=\begin{bmatrix}
A & B \\
B & C
\end{bmatrix}
\]
or, using \eqref{eq:l2}:
\[
\begin{bmatrix}
q_{2k} & q_{2k-1}\\
2q_{2k-1} & q_{2k-2}
\end{bmatrix}
\cdot
\begin{bmatrix}
q_{2k} n +1 & 1 \\
1 & 0
\end{bmatrix}
\begin{bmatrix}
q_{2k} & 2q_{2k-1}\\
q_{2k-1} & q_{2k-2}
\end{bmatrix}
=\begin{bmatrix}
A & B \\
B & C
\end{bmatrix}.
\]
Here $a=a_0= q_{2k}n +1$, so applying \eqref{rip} to the matrix noted above gives
\[
 b=\frac{2aB +C}{A} = 2(2q_{2k-1}n +1)
\]
using the relation $2q_{2k-1} +q_{2k-2} =q_{2k}$ from \eqref{3b}.
\end{proof}

\subsubsection{Formulas for cases $m=2, 3$}

The convergents of $\sqrt{6} =[2; \overline{2, 4}\,]$ for $k\ge 0$, with denominators occurring in \seqnum{A041006} and \seqnum{A041007}, are
\[
\frac{2}{1}, \, \frac{5}{2}, \, \frac{22}{9}, \, \frac{49}{20}, \, \frac{218}{89}, \, \frac{485}{198}, \, \frac{2158}{881}, \, \frac{48271}{1960}, \, \frac{21362}{8721}, \ldots.
\]
They yield these following formulas:
\begin{align*}
\sqrt{(9n+2)^2 +2(2\cdot 2n+1)} &=[9n+2; \overline{2, 4, 9n+2, 4, 2, 2(9n+2)}\,].\\
\sqrt{(89n+2)^2 +2(2\cdot 20n+1)} &=[89n+2; \overline{2, 4, 2, 4, 89n+2, 4, 2, 4, 2, 2(89n+2)}\,].\\
\sqrt{(881n+2)^2 +2(2\cdot 198n+1)} &=[881n+2; \notag \\
& \quad  \overline{2, 4, 2, 4, 2, 4, 41n+1, 4, 2, 4, 2, 4, 2, 2(881n+2)}\,].
\end{align*}

The convergents of $\sqrt{11} =[3; \overline{3, 6}\,]$ from for $k\ge 0$  with denominators occurring in \seqnum{A041014} and \seqnum{A041015}, are
\[
\frac{3}{1}, \, \frac{10}{3}, \, \frac{63}{19}, \, \frac{199}{60}, \, \frac{1257}{379}, \, \frac{3970}{1197}, \, \frac{25077}{7561}, \, \frac{79201}{23880}, \, \frac{500283}{150841}, \ldots.
\]
leading to the following formulas:
\begin{align*}
& \sqrt{(19n+3)^2 +2(2\cdot 3n+1)} =[19n+3; \overline{3, 6, 19n+3, 6, 3, 2(19n+3)}\,].\\
& \sqrt{(379n+3)^2 +2(2\cdot 60n+1)} \\
& \hspace{1cm}=[379n+3; \overline{3, 6, 3, 6, 379n+3, 6, 3, 6, 3, 2(379n+3)}\,].\\
& \sqrt{(7561n+3)^2 +2(2\cdot 1197n+1)}  \notag \\
& \hspace{1cm}=[7561n+3; \overline{3, 6, 3, 6, 3, 6, 7561n+3, 6, 3, 6, 3, 6, 3, 2(7561n+3)}\,].
\end{align*}

\section{Formulas with repeated triple $\langle 1, 1, 3\rangle$}
First, we establish a lemma to be used for proving the next theorem. We set $\alpha = 4+\sqrt{17}, \, \beta =4-\sqrt{17}$ and so $\alpha +\beta =8, \; \alpha -\beta = 2\sqrt{17}$ and get the values
\[
(\alpha -1) \alpha -(\beta -1)\beta= (\alpha -\beta) (\alpha +\beta -1)  = 14\sqrt{17},   \quad (\alpha -1) \beta -(\beta -1)\alpha = 2\sqrt{17},
\]
leading to
\[
\frac{ (\alpha -1) \alpha -(\beta -1)\beta}{\alpha -\beta } = 7,   \quad \frac{ (\alpha -1) \beta -(\beta -1)\alpha}{\alpha -\beta } =1.
\]
We can then form the following unimodular matrix:
\[
\begin{bmatrix}
7 & 2\\
4 & 1
\end{bmatrix}
=
\frac{1}{\alpha -\beta}
\begin{bmatrix}
 (\alpha -1) \alpha -(\beta -1)\beta  & 2(\alpha -\beta) \\
 4(\alpha -\beta)  & (\alpha -1) \beta -(\beta -1)\alpha
\end{bmatrix}.
\]

\begin{lemma}\label{lemma5}
We have
\[
\begin{bmatrix}
7 & 2\\
4 & 1
\end{bmatrix}^{k}
= \frac{1}{\alpha -\beta}
\begin{bmatrix}
(\alpha -1) \alpha^{k} -(\beta -1)\beta^k & 2(\alpha^{k} -\beta^k) \\
4(\alpha^{k} -\beta^k) & (\alpha -1) \beta^{k} -(\beta -1)\alpha^k
\end{bmatrix}.
\]
\end{lemma}

\begin{proof}
We use induction.

The statement is obviously true for $k=1$.  Now assume it to be true for an integer $m>1$,
\[
\begin{bmatrix}
7 & 2\\
4 & 1
\end{bmatrix}^{m}
= \frac{1}{\alpha -\beta}
\begin{bmatrix}
(\alpha -1) \alpha^{m} -(\beta -1)\beta^m & 2(\alpha^{m} -\beta^m) \\
4(\alpha^{m} -\beta^m) & (\alpha -1) \beta^{m} -(\beta -1)\alpha^m
\end{bmatrix}.
\]
Then
\begin{align*}
&
\begin{bmatrix}
7 & 2\\
4 & 1
\end{bmatrix}^{m+1}
= \frac{1}{(\alpha -\beta)^2}
\begin{bmatrix}
(\alpha -1) \alpha^{m} -(\beta -1)\beta^m & 2(\alpha^{m} -\beta^{m}) \\
4(\alpha^{m} -\beta^{m}) & (\alpha -1) \beta^{m} -(\beta -1)\alpha^{m}
\end{bmatrix} \\
& \times
\begin{bmatrix}
(\alpha -1) \alpha -(\beta -1)\beta & 2(\alpha -\beta) \\
4(\alpha -\beta) & (\alpha -1) \beta -(\beta -1)\alpha
\end{bmatrix}
= \frac{1}{(\alpha -\beta)^2}
\begin{bmatrix}
a & b\\
c & d
\end{bmatrix}.
\end{align*}
After multiplication, we obtain the expression
\begin{align*}
a = &  (\alpha -\beta) (\alpha +\beta -1) [(\alpha -1)\alpha ^{m} - (\beta -1)\beta^{m}] +8 (\alpha -\beta) (\alpha ^{m} - \beta^{m}) \\
& =  (\alpha -\beta) [(\alpha -1) \alpha ^{m +1} - (\beta -1)\beta^{m+1}  +(\alpha -1) (\beta -1) (\alpha ^{m} -\beta^{m})  +8(\alpha ^{m} -\beta^{m})] \\
& = (\alpha -\beta) [(\alpha -1) \alpha ^{m +1}  - (\beta -1)\beta^{m+1}  + (\alpha ^{m} -\beta^{m}) ((\alpha -1) (\beta -1)  +8)]\\
& = (\alpha -\beta) [(\alpha -1) \alpha ^{m +1}  - (\beta -1)\beta^{m+1} ],
\end{align*}
the last term in the penultimate line becoming 0 as $(\alpha -1) (\beta -1) =  (3+\sqrt{17}) (3 -\sqrt{17}) =-8$.
$b = 2(\alpha -\beta) [(\alpha -1)\alpha ^{m} - (\beta -1)\beta^{m}] + 2(\alpha^{m} -\beta^{m})(\alpha -\beta) =2(\alpha -\beta) (\alpha^{m+1} -\beta^{m+1})$.
Further,
$c  = 4(\alpha^{m} -\beta^{m}) (\alpha -\beta) (\alpha +\beta -1) + 4(\alpha -\beta) [(\alpha -1) \beta^{m} -(\beta -1)\alpha^{m}]
= 4(\alpha -\beta) (\alpha^{m+1} -\beta^{m+1})$.
\begin{align*}
d & = 8 (\alpha -\beta) (\alpha^{m} -\beta^{m}) + (\alpha -\beta) [(\alpha -1) \beta^{m} -(\beta -1)\alpha^{m}]  \\
& = (\alpha -\beta) [8\alpha^{m} -8\beta^{m} + (\alpha -1) \beta^{m} -(\beta -1)\alpha^{m}] \\
& = (\alpha -\beta) [\beta^{m} (-5+\sqrt{17}) + \alpha^{m} (5+\sqrt{17})] \\
& = (\alpha -\beta) [(\alpha -1) \beta^{m+1} -(\beta -1) \alpha^{m+1}].
\end{align*}
The values of $a, b, c, d$ show that the statement is true for $m+1$ also. Thus it is true for all $k$.
\end{proof}

\noindent{\bf Methodology.} Let $y =[1; 1, 3, 1, 1, 3, 1, 1, 3, \dots]$. We write it as $y=[1,1,3,y]$ or $y =\frac{7y+2}{4y+1}$. Hence the associated quadratic equation is $2 y^2 -3y -1=0$ giving the positive root $y=\frac{3+\sqrt{17}}{4}$. Now $\sqrt{17} =[4; \overline{8}\,] \Rightarrow 3+ \sqrt{17} =[7; \overline{8}\,]$. The convergents $P'_k/Q'_k \;(k\ge 0)$ of $3+\sqrt{17}$ are
\[
\frac{7}{1}, ~\frac{57}{8}, ~\frac{463}{65}, ~\frac{3761}{528}, ~\frac{30551}{4289}, ~\frac{248169}{34840}, \ldots.
\]
The numerators and denominators satisfy the recurrence $x_{k+1} = 8x_{k} +x_{k-1}$.

Let $\displaystyle \frac{p_k}{q_k}$ be the $k$-th convergent to $y$. Define $P_k =p_{3k-1}, \, Q_k = q_{3k-1}$, Then the recurrence sequences $\lbrace P_k\rbrace$, $\lbrace Q_k\rbrace$ are
\begin{align*}
P_{k} & = 8~ P_{k-1} + P_{k-2}; \quad P_{0} =7, P_{-1} =1,\\
Q_{k} & = 8~ Q_{k-1} + Q_{k-2}; \quad Q_{0} =4, Q_{-1} =0.
\end{align*}
The specially defined convergents, $P_{k} =P'_k, \; Q_{k} = 4 Q'_k$ (for $k\ge 0$) are
\[
\frac{7}{4}, ~\frac{57}{32}, ~\frac{463}{260}, ~\frac{3761}{2112}, ~\frac{30551}{17156}, ~\frac{248169}{139360}, \ldots.
\]

\begin{theorem}\label{thm4}
Let $P_k, \, Q_k$ be the numbers as defined above. 
Then for $k\in \mathbb{N}_{0}$ we have
\begin{align*}
& \sqrt{\left( \frac{P_k (2n+1) +3}{2} \right)^2 + Q_{k}(2n+1) +2}  = \left[\mystrut\right.\frac{P_k (2n+1) +3}{2}; \\
& \overline{\underbrace{1,1,3, 1,1,3,\ldots, 1,1,3}_{k+1}, \frac{P_k (2n+1)+3}{2}, \underbrace{3,1,1, 3,1,1,\ldots,3,1,1}_{k+1}, ~P_k (2n+1) +3} \left.\mystrut\right].
\end{align*}
\end{theorem}

\begin{proof} One may verify that $Q_{k+1} - Q_{k} = 4 P_{k}, \, 2 Q_{k}= P_{k} +P_{k-1}, \, 2(P_k - P_{k-1})=3Q_k +Q_{k-1}$. A few powers of the associated matrix are
\[
\begin{bmatrix}
7 & 2\\
4 & 1
\end{bmatrix}^2
=\begin{bmatrix}
57 & 16\\
32 & 9
\end{bmatrix};
\quad
\begin{bmatrix}
7 & 2\\
4 & 1
\end{bmatrix}^3
=\begin{bmatrix}
463 & 130\\
260 & 73
\end{bmatrix};
\quad
\begin{bmatrix}
7 & 2\\
4 & 1
\end{bmatrix}^4
=\begin{bmatrix}
3761 & 1056\\
2112 & 593
\end{bmatrix}.
\]
Using Lemma \ref{lemma5} we have
\begin{equation*}
\begin{bmatrix}
7 & 2\\
4 & 1
\end{bmatrix}^k
=
\frac{1}{\alpha -\beta}
\begin{bmatrix}
(\alpha -1) \alpha^{k} -(\beta -1)\beta^k & 2(\alpha^{k} -\beta^k) \\
4(\alpha^{k} -\beta^k) & (\alpha -1) \beta^{k} -(\beta -1)\alpha^k
\end{bmatrix}
:=
\begin{bmatrix}
P_{k} & Q_{k}/2\\
Q_{k} & \frac{2P_{k-1} +Q_{k-1}}{2}
\end{bmatrix}
\end{equation*}
and from this we deduce the matrix defined in Lemma \ref{lemma1}:
\[
\begin{bmatrix}
A & B\\
B & C
\end{bmatrix} =
\begin{bmatrix}
P_{k} & Q_{k}/2\\
Q_{k} & \frac{2P_{k-1} +Q_{k-1}}{2}
\end{bmatrix}
\begin{bmatrix}
\frac{P_k (2n+1) +3}{2} & 1\\
1 & 0
\end{bmatrix}
\begin{bmatrix}
P_{k} & Q_{k}\\
Q_{k}/2 & \frac{2P_{k-1} +Q_{k-1}}{2}
\end{bmatrix}.
\]
Applying Lemma \ref{lemma1} with $a=a_0=\frac{P_k (2n+1) +3}{2},$
\[
b = \frac{(P_k (2n+1) +3 ) Q_{k} +2P_{k-1} +Q_{k-1}}{P_{k}} =Q_{k}(2n+1) +2,
\]
using the relation $ 2 (P_{k} - P_{k-1}) = 3 Q_{k} + Q_{k-1} $, which can easily be proved by comparing the initial values of the sequences at the LHS and the RHS.

\end{proof}

The first three formulas yielded by Theorem \ref{thm4} follow.
\begin{align*}
&\sqrt{(7n+5)^2 +2(4n+3)} =[7n+5; ~ \overline{1, 1, 3, 7n+5, 3, 1, 1, 2(7n+5)}\,].\\
&\sqrt{(57n+30)^2 +2(32n+17)} =[57n+30;  \notag \\
&  \hspace{1cm} \overline{1, 1, 3, 1, 1, 3, 57n+30, 3, 1, 1, 3, 1, 1, 2(57n+30)}\, ].\\
&\sqrt{(463n+233)^2 +2(260n+131)} =[463n+233;  \notag \\
& \hspace{1cm} \overline{1, 1, 3, 1, 1, 3, 1, 1, 3, 463n+233, 3, 1, 1, 3, 1, 1, 3, 1, 1, 2(463n+233)}\,].
\end{align*}


\section{Repeated odd partial quotients}

\subsection{General formula for $\ell -1$ quotient $(2m+1), \, m\ge 0$}

\subsubsection {Methodology} \label{711}

As derived earlier, $\frac{(2m+1) +\sqrt{(2m+1)^2 +4}}{2} =[2m+1; \overline{2m+1}\,]$. Let $(2m+1)$ be the repeated partial quotient in the period. We will use the scf for $-(2m+1) +\sqrt{(2m+1)^2 +4}=[0; m, 1, 1, m, 4m+2]$ given in \eqref{amrik5a}. Now if we calculate the inverse of its convergent at each quotient we find that the denominator is odd at the quotient $a_1,$ at $a_2$ and at $a_4$,
while it is even at the quotient $a_3$ and at $a_5$. That is, only in the truncated fractions $[a_1, a_2, a_3]$ and $[a_1, a_2, a_3, a_4, 2a_0]$ the denominator is even. Let us define $C_k: = c_{5k-2}$ and $P_k:= p_{5k-2}, Q_k: = q_{5k-2}$ and $C^\prime_k := c_{5k}$ and $P^\prime_k := p_{5k}, Q^\prime_k =: q_{5k}$, in terms of the regular convergents.

Computing $\displaystyle c_3 = \frac{p_3}{q_3} =[m, 1, 1]$, and denoting it by $C_1=\frac{P_1}{Q_1}$, we have
\begin{equation*}
C_1=\frac{P_1}{Q_1}  =\frac{2m+1}{2} = \frac{2m+1}{2},
\end{equation*}
and its successor $\displaystyle c_8 = \frac{p_8}{q_8} = [m, 1, 1, m, 4m+2, m, 1, 1]$, denoted by $C_2=\frac{P_2}{Q_2}$, is given by
\begin{equation*}
C_2=\frac{P_2}{Q_2} =\frac{(2m+1)^4 +3(2m+1)^2 +1}{2(2m+1)^3 +4(2m+1)}.
\end{equation*}

Next, we compute $\displaystyle c_5 = \frac{p_5}{q_5} = [m, 1, 1, m, 4m+2]$ and denote it by $C^\prime_1=\frac{P^\prime_1}{Q^\prime_1}$:
\begin{equation*}
C^\prime_1=\frac{P^\prime_1}{Q^\prime_1} =[m, 1, 1, m, 4m+2]=\frac{(2m+1) [(2m+1)^2 +2]}{2[(2m+1)^2 +1]},
\end{equation*}
and its successor with two full periods $[m, 1, 1, m, 4m+2, m, 1, 1, m, 4m+2]$, the convergent $\displaystyle c_{10} = \frac{p_{10}}{q_{10}}$, denoting it by $C^\prime_2=\frac{P^\prime_2}{Q^\prime_2}$:
\begin{equation*}
C^\prime_2 = \frac{P^\prime_2}{Q^\prime_2}  = \frac{(2m+1)^6 + 5(2m+1)^4 +6(2m+1)^2 +1}{2[(2m+1)^5 + 4(2m+1)^3 + 3(2m+1)}.
\end{equation*}
Then
\begin{align*}
& P_{k+1} =M P_k +P_{k-1}; \; Q_{k+1} =M Q_k +Q_{k-1}, \quad k\ge 2, \\
& P^\prime_{k+1} = M P^\prime_k +P^\prime_{k-1}; \quad Q^\prime_{k+1} =M Q^\prime_k +Q^\prime_{k-1}, \quad k\ge 2,
\end{align*}
with $M := (2m+1) ((2m+1)^2 +3)$ \cite[p.~352] {lenshallit}.

\subsubsection{General formula}

\begin{theorem}\label{thm5}
(i) Let $P_k$ and $Q_k$ be the numbers as defined above. Then for $k\in \mathbb{N}$
\begin{align*}
& \sqrt{\left( \frac{P_k (2n-1)+ (2m+1)}{2} \right)^2 + \frac{Q_{k}(2n-1)}{2} +1} \\
&= \left[\mystrut\right.\frac{P_k (2n-1)+ (2m+1)}{2}; \overline{\underbrace{2m+1, 2m+1,\ldots,2m+1}_{3k-2}, ~ P_k (2n-1) + (2m+1)}\left.\mystrut\right].
\end{align*}
(ii) Let $P_k$ and $Q_k$ be the numbers as defined above. Then for $k\in \mathbb{N}$
\begin{align*}
& \sqrt{\left( \frac{P'_k (2n-1)+ (2m+1)}{2} \right)^2 + \frac{Q'_{k}(2n-1)}{2} +1} \\
&= \left[\mystrut\right.\frac{P'_k (2n-1)+ (2m+1)}{2};  \overline{\underbrace{2m+1, 2m+1,\ldots,2m+1}_{3k}, ~ P'_k (2n-1) + (2m+1)}\left.\mystrut\right].
\end{align*}
\end{theorem}

\begin{proof}
Part (i). Here the partial quotient $(2m+1)$ is repeated $(3k-2)$ times. In the $2\times2$ matrix approach, this just corresponds to the matrix
\[
\begin{bmatrix}
2m+1 & 1\\
1 & 0
\end{bmatrix}^{3k-2}
=
\begin{bmatrix}
u_{3k-1} & u_{3k-2}\\
u_{3k-2} & u_{3k-3}
\end{bmatrix},
\]
where $u_i$ is the solution of the recurrence $u_{i+1}=(2m+1)~u_i +u_{i-1}$ with initial values $u_0=0, \; u_1=1$ (Lemma \ref{lemma4} in Subsection \ref{genmat}).
Now the general solution of this recurrence is
\[
y_n = \lambda \alpha^n +\mu \beta^n
\]
with $\alpha = \frac{2m+1 +\sqrt{(2m+1)^2 +4}}{2}$ and $\beta =\frac{2m+1 -\sqrt{(2m+1)^2 +4}}{2}$, for arbitrary constants $\lambda$ and $\mu$. Clearly $\alpha =-\tfrac{1}{\beta}$. We can show that $y_n$ satisfies the relation
\begin{equation}
y_{n+6} = (2m+1) \left( (2m+1)^2+3 \right) y_{n+3} + y_n. \label{63r}
\end{equation}
To do this we calculate
\begin{align*}
y_{n+6}-y_n & = \lambda \cdot \left(\alpha^{n+6}-
\alpha^{n}\right) + \mu \cdot \left(\beta^{n+6}-
\beta^{n}\right) \\
& = \lambda \cdot \alpha^{n+3} \left(\alpha^{3}-
\alpha^{-3}\right) + \mu \cdot \beta^{n+3} \left(\beta^{3}-
\beta^{-3}\right) \\
& = \lambda \cdot \alpha^{n+3} \left(\alpha^{3}+
\beta^{3}\right) + \mu \cdot \beta^{n+3} \left(\beta^{3}+
\alpha^{3}\right) \\
& = \left(\alpha^{3}+
\beta^{3}\right) y_{n+3}.
\end{align*}
Note that $\alpha^3 +\beta^3 =(2m+1) \lbrace(2m+1)^2+3$ has been denoted by $M$ above.

The solution we need, $u_n$, is given by $y_n$ with $\lambda =-\mu =\frac{2}{\alpha -\beta}$:
\[
u_n = \frac{\alpha^n -\beta^n}{\sqrt{(2m+1)^2 +4}} \quad
\]
with
\[
\begin{array}{lll}
u_{-3}=(2m+1)^2+1, &  u_0=0, & u_3=(2m+1)^2+1,\\
u_{-2}=-(2m+1), & u_1=1, & u_4=(2m+1)((2m+1)^2+2), \\
u_{-1}=1, & u_2 =2m+1, & u_5 = (2m+1)^4+ 3(2m+1)^2+1, \\
\vdots & \vdots & \vdots
\end{array}
\]
As one can see, the sequence $u_{-1}$, $u_2$, $u_5, \dots,$ that satisfies \eqref{63r} is precisely the sequence $P_k$ defined in \ref{711}; more specifically,
$u_{3k-1}=P_k$. Furthermore,  the sequence $u_{-2}$, $u_1$, $u_4, \dots$, which also satisfies \eqref{63r}, is precisely the sequence $Q_k/2$; more specifically, $u_{3k-2}=Q_k/2$.

Note that for the sequence $u_{-3}$, $u_0$, $u_3$, \ldots, we have
\[
u_{3k-3}=-(2m+1) u_{3k-2}+u_{3k-1}, \mbox{ or } u_{3k-3} = P_k - \tfrac{2m+1}{2} Q_k .
\]	
So the conclusion is
\[
\begin{bmatrix}
2m+1 & 1 \\
1 & 0
\end{bmatrix}^{3k-2} =
\begin{bmatrix}
u_{3k-1} & u_{3k-2} \\
u_{3k-2} & u_{3k-3}
\end{bmatrix}
=
\begin{bmatrix}
P_k &  \frac{Q_k}{2} \\
\frac{Q_k}{2} & P_k - \tfrac{2m+1}{2} Q_k
\end{bmatrix}
=
\begin{bmatrix}
A &  B \\
B & C
\end{bmatrix}
\]
the matrix at the RHS being the one defined in \eqref{rip}. We now apply \eqref{rip}. In (i) we have that
\[
a=a_0 = \frac{P_k (2n-1)+ (2m+1)}{2}
\]
and as a consequence of what we did above, we get
\[
b = \frac{2a_0 B + C}{A}  = \frac{\left( P_k (2n-1)+ (2m+1)\right) \frac{Q_k}{2} + P_k - \frac{2m+1}{2} Q_k}{P_k}  =\frac{Q_k (2n-1)}{2} +1,
\]
which is exactly what we had to prove.

To prove part (ii), we take $3k$-th power of the matrix used previously. Note that $P_1'=u_4$, $Q_1'=2u_3$ and more generally $P_k'=u_{3k+1}, Q_k'=2u_{3k}$ and $u_{3k-1} = u_{3k+1}-(2m+1)u_{3k}$. Hence $u_{3k+1}=P_k'$, $u_{3k}=\frac{Q_k'}{2}$ and $u_{3k-1}= P_k' - \tfrac{2m+1}{2} Q_k'$. The rest of the proof proceeds along the same lines as the proof of (i).
\end{proof}

\subsection{Period with $\ell -1$ units, case $m=0$}
Setting $m=0$ in Theorem \ref{thm5} yields the following corollary:
\begin{corollary}
(i) Let $F_{3k-1}$ be the $(3k-1)$-th Fibonacci number. Then for $k\in\mathbb{N}$ and $n=1, 2, \dots$
\begin{align*}
& \sqrt{\left(\frac{F_{3k-1}~(2n-1) +1}{2} \right)^2 +  F_{3k-2}~(2n-1) +1} \\
& = \left[\mystrut\right.\frac{F_{3k-1}~(2n-1) +1}{2}; \overline{\underbrace{1,1,\ldots,1}_{3k-2}, ~ F_{3k-1}~(2n-1) +1} \left.\mystrut\right].
\end{align*}
(ii) Let $F_{3k+1}$ be the $(3k+1)$-th Fibonacci number. Then
\begin{align*}
& \sqrt{\left(\frac{F_{3k+1}~(2n-1) +1}{2} \right)^2 +F_{3k}~(2n-1) +1} \\
& = \left[\mystrut\right.\frac{F_{3k+1}~(2n-1) +1}{2}; \overline{\underbrace{1,1,\ldots,1}_{3k}, ~ F_{3k+1}~(2n-1) +1} \left.\mystrut\right].
\end{align*}
\end{corollary}
We have these recurrence relations (with $M = (2m+1)((2m+1)^2 +3) =4$):
\[
F_{3k+4} = 4 F_{3k+1} +F_{3k-2}; \; F_{3k+3} = 4 F_{3k} +F_{3k-3}; \; F_{3k+2} = 4 F_{3k-1} +F_{3k-4}.
\]
For example, $F_{13}=233$ and $F_{12}=144$ together yield ($n=1$) a dozen units:
\[
\sqrt{13834} =[117; \overline{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 234} \,].
\]

\subsection{Period with $\ell -1$ threes} Taking $m=1,$ we have
\[
\sqrt{13} =[3; \overline{1, 1, 1, 1, 6}\,]; \; -3 +\sqrt{13} =[0; \overline{1, 1, 1, 1, 6}\,].
\]
We also have
\begin{align*}
& \begin{bmatrix}
3 & 1\\
1 & 0
\end{bmatrix}^{3}
=
\begin{bmatrix}
33 & 10\\
10 & 3
\end{bmatrix};
\quad
\begin{bmatrix}
3 & 1\\
1 & 0
\end{bmatrix}^{6}
=
\begin{bmatrix}
1189 & 360\\
360 & 109
\end{bmatrix}; \\
& \begin{bmatrix}
3 & 1\\
1 & 0
\end{bmatrix}^{4}
=
\begin{bmatrix}
109 & 33\\
33 & 10
\end{bmatrix};
\quad
\begin{bmatrix}
3 & 1\\
1 & 0
\end{bmatrix}^{7}
=
\begin{bmatrix}
3927 & 1189\\
1189 & 360
\end{bmatrix}.
\end{align*}

To elucidate, we give the associated terminating continued fractions. Note that the element $a_{21}$ (2nd row, 1st column) of each matrix is $Q/2$.

\begin{example}
(i) We have $\frac{P_1}{Q_1} = (1, 1, 1) =\frac{3}{2}$. Hence
\[
\sqrt{(3n)^2 +2n} = [3n; \overline{3, 6n} \,].
\]
(ii) Subsequently we have that $\frac{P^\prime_1}{Q^\prime_1} = (1, 1, 1, 1, 6) = \frac{33}{20}$. Hence
\[
\sqrt{(33n-15)^2 +(20n-9)} =[33n-15; \overline{3, 3, 3, 2(33n-15)}\,].
\]
\end{example}

\begin{example}
(i) We have $\frac{P_2}{Q_2} =(1, 1, 1, 1, 6, 1, 1, 1)  = \frac{109}{66}$. Hence
\[
\sqrt{(109n - 53)^2 +(66n -32)} = [109n-53; \overline{3, 3, 3, 3, 2(109n-53)} \,].
\]
(ii) Subsequently we have $\frac{P^\prime_2}{Q^\prime_2} = (1, 1, 1, 1, 6, 1, 1, 1, 1, 6) = \frac{1189}{720}$. Hence
\begin{align*}
& \sqrt{(1189n -593)^2 +(720n -359)}  =[1189n -593; \overline{3, 3, 3, 3, 3, 3, 2(1189n -593)}\,].
\end{align*}
\end{example}

\begin{example}
(i) We have $\frac{P_3}{Q_3} =(1, 1, 1, 1, 6, 1, 1, 1, 1, 6, 1, 1, 1) =\frac{36\cdot109 +3}{36\cdot66 +2} = \frac{3927}{2378}$ and
\begin{align*}
\sqrt{(3927n - 1962)^2 +(2378n -1188)}  = [3927n - 1962;  \overline{3, 3, 3, 3, 3, 3, 3, 2(3927n - 1962)} \,].
\end{align*}
(ii) Subsequently we have $\frac{P^\prime_3}{Q^\prime_3} = (1, 1, 1, 1, 6, 1, 1, 1, 1, 6, 1, 1, 1, 1, 6) =\frac{36\cdot1189 +33}{36\cdot720 +20} =\frac{42837}{25940}$ and
\begin{align*}
&\sqrt{(42837n  -21417)^2 +(25940n-12969)}\\
& \hspace{1cm} =[42837n  -21417; \overline{3, 3, 3, 3, 3, 3, 3, 3, 3, 2(42837n  -21417)}\,].
\end{align*}
\end{example}

\subsection{Period with $\ell -1$ fives} The choice $m=2$ gives $-5 +\sqrt{29}$ $=[0; \overline{2, 1, 1, 2, 29}\,]$.
We list a few formulas here.
\begin{align*}
& \sqrt{(5n)^2 +2n} = [5n; \overline{5, 10n)}\, ].\\
& \sqrt{(701n - 348)^2 +(270n -134)} = [701n - 348; \overline{5, 5, 5, 5, 2(701n - 348)}\, ].\\
& \sqrt{(98145n - 49070)^2 +(37802n -18900)}  \\
& \hspace{1cm}= [98145n - 49070; \overline{5, 5, 5, 5, 5, 5, 5, 2(98145n - 49070)} \,].
\\[0.5cm]
&\sqrt{(135n-65)^2+(52n -25)} = [ 135n-65; \overline{5, 5, 5, 2(135n-65)} \,].\\
& \sqrt{(18901n -9448)^2 +(7280n-3639)}  \\
& \hspace{1cm} =[18901n -9448; \overline{5, 5, 5, 5, 5, 5, 2(18901n -9448)}\, ].\\
& \sqrt{ (2646275n -1323135)^2 +(1019252n-509625)} \\
& \hspace{1cm}= [2646275n -1323135; \overline{5, 5, 5, 5, 5, 5, 5, 5, 5, 2(2646275n -1323135)} \,].
\end{align*}


\section{Repeated even partial quotients}

We first prove a simple lemma to be used in the proof of the next theorem.
\begin{lemma}\label{lemma6}
Let $\alpha :=m +\sqrt{m^2+1}, \; \beta :=m -\sqrt{m^2+1}$ so that $\alpha +\beta =2m, \, \alpha -\beta =2 \sqrt{m^2+1}$ and $\alpha \beta =-1$. Then
\begin{equation*}
\begin{bmatrix}
2m & 1 \\
1 & 0
\end{bmatrix}^{k}
=\frac{1}{\alpha -\beta}
\begin{bmatrix}
\alpha^{k+1} -\beta^{k+1} & \alpha^{k} -\beta^{k} \\
\alpha^{k} -\beta^{k} & \alpha^{k-1} -\beta^{k-1}
\end{bmatrix}.
\end{equation*}
\end{lemma}

\begin{proof}
We prove the lemma by induction.

The statement is obviously true for $k=1$.  Assume it to be true for an integer $m>1$,
\[
\begin{bmatrix}
2m & 1 \\
1 & 0
\end{bmatrix}^{m}
=\frac{1}{\alpha -\beta}
\begin{bmatrix}
\alpha^{m+1} -\beta^{m+1} & \alpha^{m} -\beta^{m} \\
\alpha^{m} -\beta^{m} & \alpha^{m-1} -\beta^{m-1}
\end{bmatrix}.
\]
Then
\[
\begin{bmatrix}
2m & 1 \\
1 & 0
\end{bmatrix}^{m+1}
=\frac{1}{\alpha -\beta}
\begin{bmatrix}
\alpha^{m+1} -\beta^{m+1} & \alpha^{m} -\beta^{m} \\
\alpha^{m} -\beta^{m} & \alpha^{m-1} -\beta^{m-1}
\end{bmatrix}
\begin{bmatrix}
\alpha+\beta & 1 \\
1 & 0
\end{bmatrix}
=\begin{bmatrix}
a & b \\
c & d
\end{bmatrix}
\]
with $a = (\alpha^{m+1} -\beta^{m+1}) (\alpha +\beta) + \alpha^{m} -\beta^{m} =(\alpha^{m+2} -\beta^{m+2}) + (\alpha^{m} -\beta^{m}) (\alpha \beta+1)$ and so $a = \alpha^{m+2} -\beta^{m+2}$ as the other term vanishes. Furthermore, $b =\alpha^{m+1} -\beta^{m+1}$. Similarly, $c=\alpha^{m+1} -\beta^{m+1}$ and $d=\alpha^{m} -\beta^{m}$. The values of $a, b, c, d$ show that the statement is true for $m+1$ also. Thus it is true for all $k$.
\end{proof}

\subsection{Methodology}

Let $2m$ ($m\ge 1$) be the quotient that repeats in the period. We then use the scf for $\sqrt{(2m)^2 +4}$, the special case ($n=2$) of \eqref{amrik1}, for the convergents to be used. The convergents are computed from these recurrence relations ($k\ge 1$):
\begin{subequations}
\begin{align*}
& p_{2k} =m~ p_{2k-1} +p_{2k-2}; \; p_{2k+1} =4m~ p_{2k} +p_{2k-1}; \; p_0=1, \, p_1=2m,\\
& q_{2k} =m~ q_{2k-1} +q_{2k-2}; \; q_{2k+1} =4m~ q_{2k} +q_{2k-1}; \; q_0 =0, \; q_1=1,
\end{align*}
\end{subequations}
or from this one:
\begin{equation*}
p_{k+2} = M' p_{k} -p_{k-2}, \; p_{-1} =-2m, \quad q_{k+2} = M' q_{k} -q_{k-2}, \; q_{-1} =1
\end{equation*}

with $M'= 2(2m^2+1)$, and $\displaystyle  c_2 =\frac{p_2}{q_2} = [2m; m]=\frac{2m^2 +1}{m}$.

\subsection{General formula for $\ell-1$ partial quotients $2m, ~m\ge 1$ }

\begin{theorem}\label{thm6}
Let the numbers as defined above. Then for $k\in \mathbb{N}$
\begin{align*}
(i)~ & \sqrt{(q_{2k}~ n ~+m)^2 +(q_{2k-1}~ n +1)}  = \left[\strut\right.q_{2k}~ n~ +m; \overline{\underbrace{2m,2m,\ldots,2m}_{2k-1}, 2 (q_{2k}n +m)}\left.\strut\right],\\
(ii)~ & \sqrt{(q_{2k+1}~ n ~+m)^2 +(4q_{2k}~ n +1)} = \left[\strut\right.q_{2k+1}~ n~ +m; \overline{\underbrace{2m,2m,\ldots,2m}_{2k}, 2 (q_{2k+1}n +m)}\left.\strut\right].
\end{align*}
\end{theorem}

\begin{proof}
We established above in Lemma \ref{lemma6}:
\begin{equation*}
\begin{bmatrix}
2m & 1 \\
1 & 0
\end{bmatrix}^k
=\frac{1}{\alpha -\beta}
\begin{bmatrix}
\alpha^{k+1} -\beta^{k+1} & \alpha^{k} -\beta^{k} \\
\alpha^{k} -\beta^{k} & \alpha^{k-1} -\beta^{k-1}
\end{bmatrix},
\end{equation*}
where $\alpha :=m +\sqrt{m^2+1}, \; \beta :=m -\sqrt{m^2+1}$. We thus have
\begin{subequations}\label{powers}
\begin{align*}
\begin{bmatrix}
2m & 1 \\
1 & 0
\end{bmatrix}^{2k-1}
& =\frac{1}{\alpha -\beta}
\begin{bmatrix}
\alpha^{2k} -\beta^{2k} & \alpha^{2k-1} -\beta^{2k-1} \\
\alpha^{2k-1} -\beta^{2k-1}  &  \alpha^{2k-2} -\beta^{2k-2}
\end{bmatrix}, \\
\begin{bmatrix}
2m & 1 \\
1 & 0
\end{bmatrix}^{2k}
& =\frac{1}{\alpha -\beta}
\begin{bmatrix}
\alpha^{2k+1} -\beta^{2k+1} & \alpha^{2k} -\beta^{2k} \\
\alpha^{2k} -\beta^{2k} & \alpha^{2k-1} -\beta^{2k-1}
\end{bmatrix}.
\end{align*}
\end{subequations}
We find that \eqref{powers} yields only denominators but not numerators:
\begin{equation*}
\begin{bmatrix}
2m & 1 \\
1 & 0
\end{bmatrix}^{2k-1}
=
\begin{bmatrix}
2q_{2k} & q_{2k-1} \\
q_{2k-1} & 2q_{2k-2}
\end{bmatrix};
\quad
\begin{bmatrix}
2m & 1 \\
1 & 0
\end{bmatrix}^{2k}
=
\begin{bmatrix}
q_{2k+1} & 2q_{2k} \\
2q_{2k} & q_{2k-1}
\end{bmatrix}.
\end{equation*}
These are the associated closed forms for the denominators:
\begin{subequations}\label{closed1}
\begin{align*}
q_{2k-1} & = \frac{(m +\sqrt{m^2+1})^{2k-1} -(m -\sqrt{m^2+1})^{2k-1}}{2\sqrt{m^2+1}}, \\
q_{2k} & = \frac{(m +\sqrt{m^2+1})^{2k} -(m -\sqrt{m^2+1})^{2k}}{4\sqrt{m^2+1}},
\end{align*}
\end{subequations}
while those for numerators are
\begin{subequations}\label{closed2}
\begin{align*}
p_{2k-1} & = (m + \sqrt{m^2 +1})^{2k-1}  + (m - \sqrt{m^2 +1})^{2k-1}, \\
p_{2k} & =\frac{(m + \sqrt{m^2 +1})^{2k}  + (m - \sqrt{m^2 +1})^{2k}}{2}.
\end{align*}
\end{subequations}
Applying \eqref{rip} from Lemma \ref{lemma1} to the matrix proves both parts of Theorem \ref{thm6}.

For (i) we have $a_0 =a = q_{2k} n +m$ and the power $2k-1$ of the matrix giving
\[
\begin{bmatrix}
A & B \\
B & C
\end{bmatrix}
=
\begin{bmatrix}
2q_{2k} & q_{2k-1} \\
q_{2k-1} & 2q_{2k-2}
\end{bmatrix}
\]
so that
\[
b =\frac{2(q_{2k} n +m)q_{2k-1} +2q_{2k-2}}{2q_{2k}} = \frac{q_{2k} q_{2k-1}n  +mq_{2k} +q_{2k-2}}{q_{2k}} =q_{2k-1}~n +1
\]
using the relation $mq_{2k} +q_{2k-2} = q_{2k}$.

For (ii) we have $a_0 =a = q_{2k+1} n +m$ and the power $2k$ of the matrix giving
\[
\begin{bmatrix}
A & B \\
B & C
\end{bmatrix}
=
\begin{bmatrix}
q_{2k+1} & 2q_{2k} \\
2q_{2k} & q_{2k-1}
\end{bmatrix}
\]
so that
\[
b =\frac{2(q_{2k+1} n +m) 2q_{2k} +q_{2k-1}}{2q_{2k+1}} = \frac{4 q_{2k} q_{2k+1}n  +4mq_{2k} +q_{2k-1}}{q_{2k+1}} =4q_{2k}n +1
\]
using the relation $4mq_{2k} +q_{2k-1} = q_{2k+1}$.

\end{proof}

\subsection{Derivation of a combined formula for Theorem \ref{thm6} (i) \& (ii)}
The two sequences of numbers in the formula are linked by
\begin{equation*}
p_{2k} = 2m q_{2k} +q_{2k-1}; \quad p_{2k+1} =2m q_{2k+1} +4q_{2k}. \label{link1}
\end{equation*}
Expanding the square term under the root on the left of formula (i) gives us
\begin{equation}
q^2_{2k} n +m^2 +(2mq_{2k} +q_{2k-1}) n +1 = q^2_{2k} n ~+m^2 +p_{2k} n +1. \label{res1}
\end{equation}
Similarly, from (ii) we obtain
\begin{equation}
q^2_{2k+1} n +m^2 +(2mq_{2k+1} +4q_{2k}) n +1 = q^2_{2k+1} n +m^2 +p_{2k+1} n +1. \label{res2}
\end{equation}
Similarity of the RHS of both \eqref{res1} and \eqref{res2} allows us to combine (i) and (ii):
\begin{equation}
\sqrt{( (q_{k+1} n)^2 +m^2 ) +(p_{k+1} n +1)}  = \left[\right.q_{k+1} n +m; \overline{\underbrace{2m,2m,\ldots,2m}_{k}, 2 (q_{k+1}n +m)}\left.\right]. \label{combined}
\end{equation}
We note that the even-numbered convergents are given by the matrix
\[
\begin{bmatrix}
2m^2+1 & 4m (m^2+1)\\
m & 2m^2+1
\end{bmatrix}^k
=
\begin{bmatrix}
p_{2k} & 4m (m^2+1) q_{2k}\\
q_{2k} & p_{2k}
\end{bmatrix}
\]
and the odd-numbered convergents by the product
\[
\begin{bmatrix}
2m^2+1 & 4m (m^2+1)\\
m & 2m^2+1
\end{bmatrix}^k
\cdot
\begin{bmatrix}
2m & 4 (m^2+1)\\
1 & 2m
\end{bmatrix}
=
\begin{bmatrix}
p_{2k+1} & 4(m^2+1) q_{2k+1}\\
q_{2k+1} & p_{2k+1}
\end{bmatrix}.
\]

\subsection{Period with $\ell -1$ twos}
We have $\sqrt{2^2 +4} =[2; \overline{1, 4}\,]$. The recurrence relations for $k\ge 1$ are
\begin{gather*}
p_{2k} =p_{2k-1} +p_{2k-2}; \; p_{2k+1} =4p_{2k} +p_{2k-1};  \; p_0=1, \; p_1=2;\\
q_{2k} =q_{2k-1} +q_{2k-2}; \; q_{2k+1} =4q_{2k} +q_{2k-1}; \; q_0 =0, \; q_1=1.
\end{gather*}
The convergents with numerators/denominators in \seqnum{A041010} and \seqnum{A041011} are
\[
\frac{2}{1}, ~\frac{3}{1}, ~\frac{14}{5}, ~\frac{17}{6}, ~\frac{82}{29}, ~\frac{99}{35}, ~\frac{478}{169}, ~\frac{577}{204}, ~\frac{2786}{985}, \ldots.
\]
Formula \eqref{combined} and four of the convergents give us
\begin{align*}
& \sqrt{n^2 +1^2 +(3n +1)} =[n+1; \overline{2, 2(n+1)}\,],\\
& \sqrt{(5n)^2 +1^2 +(14n +1)} =[5n+1; \overline{2, 2, 2(5n+1)}\,],\\
& \sqrt{(6n)^2 +1^2 +(17n +1)} =[6n+1; \overline{2, 2, 2, 2(6n+1)}\,],\\
& \sqrt{(29n)^2 +1^2 +(82n +1)} =[29n+1; \overline{2, 2, 2, 2, 2(29n+1)}\,].
\end{align*}

\subsection{Period with $\ell -1$ fours}

We have $\sqrt{4^2 +4} =[4; \overline{2, 8}\,]$. The convergents with numerators/denominators in \seqnum{A041030} and \seqnum{A041031} are
\[
\frac{4}{1}, ~\frac{9}{2}, ~\frac{76}{17}, ~\frac{161}{36}, ~\frac{1364}{305}, ~\frac{2889}{646}, ~\frac{24476}{5473}, ~\frac{51841}{11592}, ~\frac{439204}{98209}, \ldots.
\]
Formula \eqref{combined} and three of the convergents yield
\begin{align*}
& \sqrt{(2n)^2 +2^2 +(9n +1)} =[2n+2; \overline{4, 2(2n+2)}\,],\\
& \sqrt{(17n)^2 +2^2 +(76n +1)} =[17n+2; \overline{4, 4, 2(17n+2)}\,],\\
& \sqrt{(36n)^2 +2^2 +(161n +1)} =[36n+2; \overline{4, 4, 4, 2(36n+2)}\,].
\end{align*}

\subsection{Period with $\ell-1$ sixes}

We have $\sqrt{6^2 +4} =[6; \overline{3, 12}\,]$. Its convergents with numerators/denominators in \seqnum{A041066} and \seqnum{A041067} are
\[
\frac{6}{1}, ~\frac{19}{3}, ~\frac{234}{37}, ~\frac{721}{114}, ~\frac{8886}{1405}, ~\frac{27379}{4329}, ~\frac{337434}{53353}, \ldots.
\]
Formula \eqref{combined} and three of the convergents lead to
\begin{align*}
& \sqrt{(3n)^2 +3^2 +(19n+1)} =[3n+3; \overline{6, 2(3n+3)}\,],\\
& \sqrt{(37n)^2 +3^2 +(234n+1)} =[37n+3; \overline{6, 6, 2(37n+3)}\,],\\
& \sqrt{(114n)^2 +3^2 +(721n+1)} =[114n+3; \overline{6, 6, 6, 2(114n+3)}\,].
\end{align*}

\section{Algorithm involving five sequences}\label{algorithm}

\subsection{Methodology and general formula}

Until now we dealt with formulas that involved only two sequences $P_k, \, Q_k$. We found empirically that repeated blocks having three (excepting $(1, 1, 3)$) or more numbers cannot be formulated using only these two sequences but need a third auxiliary sequence $R_k$ related to $P_k$. Two more sequences $S_k$ and $T_k$ are computed further on. The computation of $S_k$ and $T_k$ involves the solution of certain linear Diophantine equations.

Let $\mathcal{B}=(b_0, b_1, \dots, b_j)$ with $b_i$ positive integers not all equal. Let $\overleftarrow{\mathcal{B}}=(b_j, b_{j-1}, \dots, b_0)$ be the reverse of $\mathcal{B}$. Let $y$ denote the purely periodic continued fraction: $y =[\,\overline{b_0, b_1, \dots, b_j}\,]$. We write it as $y=[b_0, b_1, \dots, b_j, y]$, which leads to a quadratic equation of the form $cy^2 -by -a=0$ with positive root $y =\frac{b+\sqrt{b^2+4ac}}{2c}$.

Empirical analysis revealed this \emph{necessary condition} for the occurrence of block $\mathcal{B}$ in the next theorem: $\mathcal{B}$ can occur in the formula \emph{only if} the coefficient of $y^2$ is twice the absolute value of the constant term in the equation.

We now define $\frac{P_0}{Q_0} = \text{SCF}[b_0, b_1, \dots, b_j]$ and $\frac{P_1}{Q_1} = \text{SCF}[b_0, b_1, \dots, b_j, b_0, b_1, \dots, b_j]$ and so on. In general, $P_k$ and $Q_k$ are defined by
\begin{equation}\label{theprod}
\begin{bmatrix}
b_0 & 1\\
1 & 0
\end{bmatrix}
\begin{bmatrix}
b_1 & 1\\
1 & 0
\end{bmatrix}
\begin{bmatrix}
b_2 & 1\\
1 & 0
\end{bmatrix}
\cdots
\begin{bmatrix}
b_j & 1\\
1 & 0
\end{bmatrix}
=
\begin{bmatrix}
P_0 & V_0\\
Q_0 & R_0
\end{bmatrix}
\ \ \mbox{and} \ \
\begin{bmatrix}
P_k & V_k\\
Q_k & R_k
\end{bmatrix} =
\begin{bmatrix}
P_0 & V_0\\
Q_0 & R_0
\end{bmatrix}^{k+1} .
\end{equation}
Note that using these notations the quadratic equation $cy^2-by-a=0$ equals $ Q_0 y^2 - (P_0-R_0)y - V_0=0$.

From now on we will assume that $Q_0 = 2V_0$ with as immediate consequence that $Q_k=2V_k$.
It follows from \cite[p.~352]{lenshallit} that $P_k$, $Q_k$, and $R_k$ are solutions of the recurrence relation
\[
y_{k+1} = M y_{k} + (-1)^j y_{k-1}, k=0,1,2,\ldots,
\]
with initial values $P_{-1}=1$, $Q_{-1}=0$, $R_{-1}=1$ and with $P_0, Q_0$ and $R_0$ defined by the product in \eqref{theprod}.
Furthermore, $M$ is equal to the trace of
\[
\begin{bmatrix}
	P_0 & \tfrac{1}{2}Q_0\\
	Q_0 & R_0
\end{bmatrix}.
\]
Note that $M=\frac{Q_1}{Q_0}$.

A fourth sequence of numbers $S_{k}$ is obtained defining $S_{k}$ as the least positive integer such that $P_k \mid (Q_k\cdot S_k +R_k)$.  From these four sequences, we deduce a fifth sequence of numbers $T_k$ using the formula
\[
T_k = \frac{Q_k\cdot S_k +R_k}{P_k}.
\]

\begin{theorem}\label{thm7}
Let $P_k, Q_k, S_k, T_k, \mathcal{B}, \overleftarrow{\mathcal{B}}$ be the numbers/blocks as defined above. Then for $k, n\in \mathbb{N}_0$
\begin{align*}
& \sqrt{(P_k n + S_k)^2 + 2(Q_{k} n + T_k)}  = \left[\right.P_k n + S_k; \\
& \hspace{1cm} \overline{\underbrace{\mathcal{B}, \mathcal{B}, \ldots, \mathcal{B}}_{k+1}, P_k n + S_k, \underbrace{ \overleftarrow{\mathcal{B}}, \overleftarrow{\mathcal{B}}, \ldots, \overleftarrow{\mathcal{B}}}_{k+1}, ~2(P_k n + S_k)} \left.\right].
\end{align*}
\end{theorem}

\begin{proof}
The proof again uses \eqref{rip}. In this case
\[
\begin{bmatrix}
A & B \\
B & C
\end{bmatrix}
=
\begin{bmatrix}
P_k & \tfrac{1}{2}Q_k\\
Q_k & R_k
\end{bmatrix}
\cdot
\begin{bmatrix}
P_k n + S_k & 1 \\
1 & 0
\end{bmatrix}
\cdot
\begin{bmatrix}
P_k & Q_k\\
\tfrac{1}{2}Q_k & R_k
\end{bmatrix}
\]
from which it follows that
\[
\frac{2(P_k n+S_k)B+C}{A}=2Q_k n + 2\frac{Q_k S_k +R_k}{P_k}.
\]
For the second term to be an integer it is necessary that $S_k$ is chosen in such a way that $P_k$ divides $Q_k S_k +R_k$, or that the sequence $T_k$ defined above consists only of integers. Hence we are looking for an integer solution $x=T_k$, $y=S_k$ with $x, y>0$ of the linear equation
\begin{equation}\label{linear}
P_k \cdot x - Q_k \cdot y = R_k.
\end{equation}
Now it is well known that such a solution exists if $(P_k,Q_k) =1$ \cite[p.~77]{davenport}. That this condition is satisfied is a consequence of \eqref{theprod}:
\begin{equation} \label{det}
\textrm{det} \begin{bmatrix}
P_k & \tfrac{1}{2}Q_k\\
Q_k & R_k
\end{bmatrix} =
\textrm{det} \begin{bmatrix}
P_0 & \tfrac{1}{2}Q_0\\
Q_0 & R_0
\end{bmatrix}^{k+1}
= \left((-1)^{j+1}\right)^{k+1} .
\end{equation}
A common factor of $P_k$ and $Q_k$ is a factor of this determinant and hence has to divide 1. Now it is easy to see from \eqref{det} (see also \cite[p.~78]{davenport}) that the integer solutions of the linear equation
\[
P_k \cdot \hat{x} - Q_k \cdot \hat{y} = \left((-1)^{j+1}\right)^{k+1}
\]
are determined by the denominator and the numerator of the penultimate convergent $\frac{\frac{1}{2}Q_k}{R_k}$ of the continued fraction of $\frac{P_k}{Q_k}$:
\[
\hat{x} = R_k + m Q_k, \qquad \hat{y} = \frac{1}{2}Q_k + m P_k
\]
(with $m$ an arbitrary integer). Combining this with \eqref{linear} we immediately see that
\[
T_k \equiv  \left((-1)^{j+1}\right)^{k+1} \cdot R_k^2 \pmod  {Q_k}, \qquad
S_k \equiv \left((-1)^{j+1}\right)^{k+1} \cdot \frac{1}{2} Q_k R_k \pmod {P_k}.
\]
\end{proof}

\begin{remark}
Let the positive root of the equation under review be denoted by $\frac{p +\sqrt{d}}{q}$. We found that
\begin{itemize}
\item $M = 2a_0$ and $P_0 =p+a_0$ if $\sqrt{d} =[a_0; \overline{2a_0}\,]$.

\item $M =2+2a_0$ and $P_0 =p+a_0 +1$ if $\sqrt{d} =[a_0; \overline{1, 2a_0}\,]$.

\item $M =2+4a_0$ and and $P_0 =2p+2a_0+1$ if $\sqrt{d} =[a_0; \overline{2, 2a_0}\,]$.
\end{itemize}
\end{remark}

\subsection{Two illustrative examples}

\subsubsection{$\mathcal{B}$= (1, 1, 2, 3)} The characteristic equation is $10y^2 -14y -5=0$ with positive root $\frac{7+\sqrt{99}}{10}$ and scf expansion $\sqrt{99} =[9; \overline{1, 18}\,]$. SCF $[1,1,2,3] = \frac{17}{10}$ and SCF $[1,1,2,3,1,1,2,3]= \frac{339}{200}$ so that the multiplier is $M= 200/10 =20 = 18 +2$.

\[
\frac{P_k}{Q_k} = \frac{17}{10}, \, \frac{339}{200}, \,  \frac{6763}{3990}, \, \frac{134921}{79600}, \, \frac{2691657}{1588010}, \ldots.
\]

\begin{align*}
R_k & = 3, 59, 1177, 23481, 468443, \ldots. \\
S_k & = 15, 137, 1354, 80954, 2153327,\ldots. \\
T_k & = 9, 81, 799, 47761, 1270409, \ldots.
\end{align*}
For $n=0, 1, 2, \ldots$, we have these first three formulas:
\begin{align*}
& \sqrt{(17n +15)^2 + 2(10n +9) } \notag =[17n +15; \\
& \hspace{1cm} \overline{1, 1, 2, 3, 17n +15, 3, 2, 1, 1, 2(17n +15)}\,], \\
& \sqrt{(339n +137)^2 + 2(200n +81) } \notag =[339n +137; \\
& \hspace{1cm} \overline{(1, 1, 2, 3)^2, 339n +137, (3, 2, 1, 1)^2, 2(339n +137)}\,],\\
& \sqrt{(6763n +1354)^2 + 2(3990n +799) } \notag = [6763n +1354;\\
& \hspace{1cm} \overline{(1, 1, 2, 3)^3,~ 6763n +1354, (3, 2, 1, 1)^3,~ 2(6763n +1354)}\,].
\end{align*}

\subsubsection{$\mathcal{B}$ = (1, 3, 1, 1, 2)} 
The equation here is $18y^2 -16y -9=0$ with root $\frac{8+\sqrt{226}}{18}$
and expansion $ \sqrt{226}= [15; \overline{30}\,]$. Now SCF$[1,3,1,1,2] =
\frac{23}{18}$ and SCF $[1,3,1,1,2,1,3,1,1,2]= \frac{691}{540}$, which
yield $M=540/18=30$.

\[
\frac{P_k}{Q_k} = \frac{23}{18}, \, \frac{691}{540}, \, \frac{20753}{16218}, \, \frac{623281}{487080}, \, \frac{18719183}{14628618},
\ldots.
\]

\begin{align*}
R_k & = 7, 211, 6337, 190321, 5710807, \dots. \\
S_k & = 6, 308, 18448, 484775, \dots. \\
T_k & = 5, 241, 14417, 378841, \dots.
\end{align*}
For $n=0, 1, 2, \dots,$ we have
\begin{align*}
& \sqrt{(23n+6)^2 +2 (18n+5)} =[23n+6; \notag \\
& \hspace{1cm} \overline{1, 3, 1, 1, 2, 23n+6, 2, 1, 1, 3, 1, 46n+12}\,], \\
& \sqrt{(691 n + 308)^2 +2(540 n + 241)} \notag = [691 n + 308;\\
& \hspace{1cm}\overline{(1, 3, 1, 1, 2)^2,~ 691 n + 308, (2, 1, 1, 3, 1)^2,~ 2(691 n + 308)}\,], \\
& \sqrt{(20753n +18448)^2 +2(16218n +14417)} \notag = [20753n +18448;\\
& \hspace{1cm}\overline{(1, 3, 1, 1, 2)^3,~20753n +18448, (2, 1, 1, 3, 1)^3,~ 2(20753n +18448)}\,].
\end{align*}

\subsection{On the composition of block $\mathcal{B}$}

We found  the blocks initially by inspecting all the scf expansions of $\sqrt{d}$ for $d\le 1200$. However, one can take any arbitrary string of numbers and verify whether the equation obtained therefrom is of the form $2ay^2 -by -a=0$. If yes, then that is a candidate, else not. Future work may lead to a more systematic way for producing these blocks. We give here some blocks of various lengths. They have been ordered on the basis of rising sums of the numbers in a block. The individual lists will grow as $d$ rises. The length of the block  will go on rising indefinitely.

\subsubsection{Triples}
We found that the only triple candidate is of the form $(n, 1, 2n+1), \; n \in \mathbb{N}$, whose characteristic equation is given by $y=[n, 1, 2n+1, y ] \Rightarrow 2(n+1)y^2 -2n(n+2)y -(n+1)=0$.

\subsubsection{Quadruples}
(1, 1, 2, 3), (1, 4, 2, 2), (2, 2, 1, 4), (2, 1, 2, 5), (1, 6, 3, 2), (3, 2, 1, 6), (3, 1, 2, 7), (1, 10, 5, 2), (2, 8, 4, 4), (4, 4, 2, 8).

\subsubsection{Quintuples}
(1, 3, 1, 1, 2), (2, 3, 1, 1, 4), (1, 7, 1, 3, 2), (2, 5, 1, 2, 4), (3, 1, 2, 2, 7), (3, 7, 1, 3, 6).

\subsubsection{Sextuples}
(1, 3, 2, 1, 1, 2), (1, 1, 1, 1, 3, 3), (1, 5, 2, 1, 2, 2), (1, 1, 5, 2, 1, 3), (2, 1, 3, 1, 1, 5), (2, 1, 1, 1, 3, 5), (1, 6, 1, 2, 3, 2), (1, 1, 11, 5, 1, 3), (5, 2, 1, 2, 1, 10), (2, 2, 7, 14, 1, 4).

\subsubsection{Septuples}
(1, 3, 2, 2, 1, 1, 2), (1, 4, 1, 1, 3, 2, 2), (1, 1, 1, 2, 1, 6, 3), (2, 3, 2, 2, 1, 1, 4), (5, 4, 1, 1, 3, 2, 10).

\subsubsection{Octuples}
(1, 1, 2, 3, 1, 1, 2, 3), (1, 3, 1, 3, 7, 1, 1, 2), (2, 2, 1, 4, 2, 2, 1, 4).

\section{Acknowledgments}
We would like to thank Jeffrey Shallit for suggesting the matrix method to establish properties of continued fractions. We are also thankful to the anonymous referee for drawing our attention to Schinzel's theorem in \cite{schinzel} and two related papers \cite{chengd05, chengd12} of Cheng et al.

\begin{thebibliography}{99}
\bibitem{adam} B.\ Adamczewski and Y.\ Bugeaud, Palindromic continued fractions, \emph{An. de l'Institut Fourier}, {\bf 57} (2007), 1557--1574. Available at \url{http://aif.cedram.org/item?id=AIF_2007__57_5_1557_0}.
\bibitem{allouche} J.-P. Allouche and J. Shallit, \emph{Automatic Sequences: Theory, Applications, Generalizations}, Cambridge University Press, 2003.
\bibitem{arnold} V. I. Arnold, Lengths of periods of continued fractions of square roots of integers, \emph{Functional Analysis and Other Mathematics}, {\bf 2} (2009), 151--164. 
Available at \url{https://doi.org/10.1007/s11853-009-0031-x}.
\bibitem{bombpoor} E.\ Bombieri and A.\ J.\ van der Poorten, Continued fractions of algebraic numbers, in W.\ Bosma and A.\ van der Poorten (eds) \emph{Computational Algebra and Number Theory}, Springer, 1995, pp.\ 137--152.
\bibitem{borwein} J.\ Borwein, A.\ J.\ van der Poorten, J.\ Shallit, and W.\ Zudilin, \emph{Neverending Fractions: An Introduction to Continued Fractions}, Cambridge University Press, 2014.
\bibitem{chengd05} K.\ Cheng and H.\ Williams, Some results concerning certain periodic continued fractions, \emph{Acta Arith.} {\bf 117} (2005), 247--264. 
Available at \url{https://www.impan.pl/en/publishing-house/journals-and-series/acta-arithmetica/all/117/3}.
\bibitem{chengd12} K.\ H.\ F.\ Cheng, R.\ K.\ Guy, R.\ Scheidler, and H.\ C.\ Williams, Classification and symmetries of a family of continued fractions with bounded period length, \emph{J. Aust. Math. Soc.} {\bf 93} (2012), 53--76.
\bibitem{davenport} H.\ Davenport, \emph{The Higher Arithmetic: An Introduction to the Theory of Numbers}, Cambridge University Press, 2008.
\bibitem{frame} J.\ S.\ Frame, Continued fractions and matrices, \emph{Amer. Math. Monthly } {\bf 56} (1949), 98--103.
\bibitem{hurwitz} A.\ Hurwitz and N.\ Kritikos, \emph{Lectures on Number Theory}, Springer, 1986.
\bibitem{jacobwil} M.\ J.\ Jacobson and H.\ C.\ Williams, \emph{Solving the Pell Equation}, CMS Books in Mathematics, Springer, 2009.
\bibitem{khovanskii} A.\ N.\ Khovanskii, Continued fractions, in L.\ A.\ Lyusternik and A.\ R.\ Yanpol'skii (eds), \emph{Mathematical Analysis: Functions, Limits, Series, Continued Fractions}, Pergamon Press, 1965, pp.\ 241--303.
\bibitem{kraitchik} M.\ Kraitchik, \emph{Th\'{e}orie des Nombres II}, Gauthier-Villars, 1926.
\bibitem{lenshallit} H.\ W.\ Lenstra, Jr. and J.\ O.\ Shallit, Continued fractions and linear recurrences. \emph{Math. Comp.} {\bf 61} (1993), 351--354.
\bibitem{LeVeque} W.\ J.\ LeVeque, \emph{Fundamentals of Number Theory.} Addison-Wesley, 1977.
\bibitem{niven} I.\ Niven, H.\ S.\ Zuckerman and H.\ L.\ Montgomery, \emph{An Introduction to the Theory of Numbers.} J. Wiley \& Sons, 1991.
\bibitem{perron} O.\ Perron, \textit{Die Lehre von den Kettenbr\"{u}chen}, B.\ G.\ Teubner, 1913.
\bibitem{poorten85} A.\ J.\ van der Poorten, An introduction to continued fractions, in J.\ H.\ Loxton A.\ J.\ van der Poorten (ed.) \emph{Diophantine Analysis: Proceedings of the Number Theory Section of the 1985 Australian Mathematical Society Convention},  Cambridge University Press, 1986, pp.\ 99--138.
\bibitem{poorten90} A.\ J.\ van der Poorten, Notes on continued fractions and recurrence sequences, in J.\ H.\ Loxton (ed.) \emph{Number Theory and Cryptography}, Cambridge University Press, 1990, pp.\ 86--97.
\bibitem{poorten99} A.\ J.\ van der Poorten and H.\ C.\ Williams, On certain continued fraction expansions
of fixed period length, \emph{Acta Arith.} {\bf 89} (1999), 23--35. Available at \url{http://matwbn.icm.edu.pl/ksiazki/aa/aa89/aa8913.pdf}.
\bibitem{rippon} P.\ J.\ Rippon and H.\ Taylor, Even and odd periods in continued fractions of square roots, \emph{Fibonacci Quart. } {\bf 42} (2004), 170--180. Available at \url{https://www.fq.math.ca/Papers1/42-2/quartrippon02_2004.pdf}.
\bibitem{rockett1} A.\ M.\ Rockett and P.\ Sz\"{u}sz, On the lengths of the periods of the continued fractions of square-roots of integers, \emph{Forum Math.} {\bf 2} (1990), 119--123.  Available at \url {https://www.digizeitschriften.de/id/481110151_0002%7Clog12}.
\bibitem{schinzel} A.\ Schinzel, On some problems of the arithmetical theory of continued fractions. \emph{Acta Arith.} {\bf 6} (1961), 293--413. Available at \url{http://matwbn.icm.edu.pl/ksiazki/aa/aa6/aa643.pdf}.
\bibitem{sierpinski} W.\ Sierpi\'nski, \emph{Elementary Theory of Numbers}, North Holland, PWN-Polish Scientific Publishers, 1988.
\bibitem{sloane}  N.\ J.\ A.\ Sloane et al., {\it The On-Line Encyclopedia of Integer Sequences}. Available at \url{https://oeis.org}, 2022.
\end{thebibliography}
\bigskip
\hrule
\bigskip
	
\noindent 2020 {\it Mathematics Subject Classification}: Primary 11A55. Secondary 11Y65.
	
\medskip

\noindent \emph{Keywords}: continued fraction, quadratic irrational, square root, Fibonacci number, recurrence sequence.


\bigskip
\hrule
\bigskip

\noindent (Concerned with sequences
\seqnum{A000129},
\seqnum{A001333},
\seqnum{A002530},
\seqnum{A002531},
\seqnum{A014106},
\seqnum{A041006},
\seqnum{A041007},
\seqnum{A041010},
\seqnum{A041011},
\seqnum{A041014},
\seqnum{A041015},
\seqnum{A041030},
\seqnum{A041031},
\seqnum{A041066},
\seqnum{A041067},
\seqnum{A056220},
\seqnum{A080856},
\seqnum{A081585},
\seqnum{A142463}.)

\bigskip
\hrule
\bigskip

\vspace*{+.1in}
\noindent
Received  August 17 2022;
revised versions  received  September 21 2022; October 12 2022.
Published in {\it Journal of Integer Sequences}, March 2 2023.

\bigskip
\hrule
\bigskip

\noindent
Return to
\htmladdnormallink{Journal of Integer Sequences home page}{https://cs.uwaterloo.ca/journals/JIS/}.
\vskip .1in


\end{document}

                                                                                




