[step:Define the convergents and complete quotients of $\sqrt{D}$]
Let
\begin{align*}
\sqrt{D} = [a_0; a_1, a_2, a_3, \dots]
\end{align*}
be the simple continued fraction expansion of $\sqrt{D}$, with minimal period $\ell$ after $a_0$. Define the convergent numerator and denominator sequences $(p_n)_{n \geq -2}$ and $(q_n)_{n \geq -2}$ by
\begin{align*}
p_{-2} &= 0, & p_{-1} &= 1, & p_n &= a_n p_{n-1} + p_{n-2}, \\
q_{-2} &= 1, & q_{-1} &= 0, & q_n &= a_n q_{n-1} + q_{n-2}
\end{align*}
for every integer $n \geq 0$. Thus
\begin{align*}
\frac{p_n}{q_n}
\end{align*}
is the $n$th convergent of $\sqrt{D}$.
For the complete quotients, define integer sequences $(P_n)_{n \geq 0}$ and $(Q_n)_{n \geq 0}$ by
\begin{align*}
P_0 &= 0, & Q_0 &= 1, \\
P_{n+1} &= a_n Q_n - P_n, & Q_{n+1} &= \frac{D - P_{n+1}^2}{Q_n}.
\end{align*}
Then the $n$th complete quotient is
\begin{align*}
\alpha_n = \frac{P_n + \sqrt{D}}{Q_n}.
\end{align*}
We use the [Complete-Quotient Norm Formula for Periodic Continued Fractions](/theorems/complete-quotient-norm-formula-for-periodic-continued-fractions) with the indexing convention just defined. In precisely this convention, applied to the nonsquare integer $D > 0$ and to the simple continued fraction of $\sqrt{D}$, it asserts that the recursively defined quantities $P_n$ and $Q_n$ are integers, that $Q_n > 0$ for every $n \geq 0$, that
\begin{align*}
p_n^2 - Dq_n^2 = (-1)^{n+1}Q_{n+1}
\end{align*}
for every $n \geq 0$, and that $Q_m = 1$ with $m > 0$ precisely when $m$ is a multiple of the minimal period $\ell$. The hypotheses of that result are exactly the hypotheses already in force here: $D$ is a positive nonsquare integer, the expansion is the simple continued fraction expansion of $\sqrt{D}$, and the sequences $p_n,q_n,P_n,Q_n$ use the displayed recurrence and indexing convention. The explicit restatement fixes the indexing dependency: every later use of the theorem refers to this displayed convention.
[/step]