TITLE: Last term of repeating continued fraction expansion
QUESTION [9 upvotes]: Once again, working with stable vector bundles on $\mathbb{P}^2$ I have run into a question that is really out of my area.  (Thanks to everybody who helped out with my last question!)
Let $D>9$ be a rational number which is not a square, and consider the quadratic irrational 
$$\xi = \frac{-3 + \sqrt{D}}{2},$$
(I'd be willing to force $D$ to be an integer, and even to assume $D \equiv 5 \pmod{8}$, but I don't think it matters).  Let $r$ be the positive integer such that 
$$(2r+1)^2 < D < (2r+3)^2.$$
Numerous examples with Mathematica suggest that the continued fraction expansion of $\xi$ takes the form 
$$\xi = [r-1;\overline{a_1,\ldots,a_k}],$$ where the last term of the repeating part is $a_k = 2r+1$.  
For my particular situtation, I'd be happy enough to know that the number $2r+1$ appears somewhere in the expansion.
As I know almost nothing about continued fractions aside from statements of the basic results, I haven't the slightest idea how to prove something like this.  I also don't have a source which does much more advanced things than show that the expansion of a quadratic irrational always repeats.  Are statements like this well-known?  And where should I look for more advanced theory relevant to this problem?
In case it helps, the original form I came to this number is as follows.  Put  $$ q = \frac{1}{8}(D-5). $$ Then $\xi$ is a solution of the equation $$\frac{1}{2}(x^2+3x+1) = q.$$ Thanks!
EDIT: At request, here is what Mathematica gives for the continued fractions for some $D$:
$D=5: [0;-2,\overline{-1}]$ (but I am requiring $D>9$)
$D=10: [0;\overline{12,3}]$
$D=13: [0;\overline{3}]$
$D=141: [4;\overline{2,3,2,11}]$
(need more examples? Just ask!)

REPLY [13 votes]: It's known that a quadratic irrational has a purely periodic continued fraction expansion if and only if it is greater than $1$ and its conjugate is between $-1$ and $0$.  Your observation amounts to proving that $r+2 + (-3+\sqrt{D})/2$ has this property (note that adding $r + 2$ makes it start with $2r+1$).  This amounts to checking that $-1 < (2r+1 - \sqrt{D})/2 < 0$, which is equivalent to your assumption that $(2r+1)^2  < D <  (2r+3)^2$.