0% found this document useful (0 votes)
10 views

mariusjp

This paper discusses the period length of the continued fraction expansion of a number n, presenting results on average period lengths and maximum lengths based on numerical experiments. It includes definitions, theorems, and proofs related to the periodicity of continued fractions and their relation to quadratic equations with integer coefficients. The author also explores specific cases for irrationals of the form √D, providing algorithms for calculating continued fraction digits.

Uploaded by

aqsa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

mariusjp

This paper discusses the period length of the continued fraction expansion of a number n, presenting results on average period lengths and maximum lengths based on numerical experiments. It includes definitions, theorems, and proofs related to the periodicity of continued fractions and their relation to quadratic equations with integer coefficients. The author also explores specific cases for irrationals of the form √D, providing algorithms for calculating continued fraction digits.

Uploaded by

aqsa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Period of the Continued Fraction of n


Marius Beceanu

February 5, 2003

Abstract
This paper seeks to recapitulate the known facts
√ about the length of
the period of the continued fraction expansion of n as a function of n
and to make a few (possibly) original contributions. I have
√ established
a result concerning the average period length for k < n < k + 1,
where k is an integer, and, following numerical experiments, tried to
formulate the best possible bounds for this average length and for the
maximum
√ length
√ of the period of the continued fraction expansion of
n, with b nc = k.

Many results used in the course of this paper are borrowed from [1] and
[2].

1 Preliminaries
Here are some basic definitions and results that will prove useful throughout
the paper. They can also be probably found in any number theory intro-
ductory course, but I decided to include them for the sake of completeness.

Definition 1.1 The integer part of x, or bxc, is the unique number k ∈ Z


with the property that k ≤ x < k + 1.

Definition 1.2 The continued fraction expansion of a real number x is the


sequence of integers (an )n∈N obtained by the recurrence relation
1
x0 = x, an = bxcn , xn+1 = , for n ∈ N.
xn − an
Let us also construct the sequences

P0 = a0 , Q0 = 1,
P1 = a0 a1 + 1, Q1 = a1 ,

1

2 Period of the Continued Fraction of n

and in general

Pn = Pn−1 an + Pn−2 , Qn = Qn−1 an + Qn−2 ,

for n ≥ 2. It is obvious that, since an are positive, Pn and Qn are strictly


increasing for n ≥ 1 and both are greater or equal to Fn (the n-th Fibonacci
number). Let us define the n-th convergent

1
Rn = a0 +
1
a1 +
1
a2 +
.. 1
.+
an .

Theorem 1.1 The following relations hold for n ≥ 2:

Pn Pn−1 an + Pn−2 Pn−1 xn + Pn−2


Rn = = ; x= .
Qn Qn−1 an + Qn−2 Qn−1 xn + Qn−2

The proof can be easily made by induction, and is also to be found in [2,
Sect. 5.2.4]. Other well-known facts are that

Pn−1 Qn − Qn−1 Pn = (−1)n .

(also proven by induction) and that

Pn Pn xn+1 + Pn−1 Pn (−1)n


x− = − =
Qn Qn xn+1 + Qn−1 Qn Qn (Qn xn+1 + Qn−1 )
1

Qn Qn+1 )

It follows that limn→∞ Rn = x. In particular, the last result implies that


two numbers whose continued fraction expansions coincide must be equal.

2 Periodicity of continued fractions


Theorem 2.1 The continued fraction expansion of a real number x is pe-
riodic from a point onward iff x is the root of some quadratic equation
ax2 + bx + c = 0 with integer coefficients.
Marius Beceanu 3

Proof The sufficiency is easier to prove. Indeed, if we know that an = an+p


for all n ≥ N , then let us note that xN and xN +p have the same continued
fraction and thus are equal. On the other hand, we know that
1 P̃p−1 xN +p + P̃p−2
xN = aN + =
1 Q̃p−1 xN +p + Q̃p−2
aN +1 +
1
aN +2 +
.. 1
.+
xN +p
and therefore it satisfies the second-degree equation
Q̃p−1 x2N + (Q̃p−2 − P̃p−1 )xN − P̃p = 0.
PN −1 xN +PN −2
At the same, let us remember that x = QN −1 xN +QN −2 . By a trivial compu-
−QN −2 x+PN −2
tation we obtain that xN = QN −1 x−PN −1 .Therefore x satisfies a second-
degree equation with integer coefficients too, namely

Q̃p−1 (−QN −2 x+PN −2 )2 +(Q̃p−2 −P̃p−1 )(−QN −2 x+PN −2 )(QN −1 x−PN −1 )


− P̃p (QN −1 x − PN −1 )2 = 0.
The converse is slightly more difficult to prove. Assume that x satisfies
the equation f (x) = ax2 + bx + c = 0. Then, since x = PPn−1 n−1 xn +Pn−2
xn +Pn−2 , it
follows that each of the remainders xn , n ≥ 2, also satisfies the second-
degree equation

a(Pn−1 xn + Pn−2 )2 + b(Pn−1 xn + Pn−2 )(Qn−1 xn + Qn−2 )


+ c(Qn−1 xn + Qn−2 )2 = 0
or fn (xn ) = An x2n + Bn xn + Cn = 0, where I have denoted
2
An = aPn−1 + bPn−1 Qn−1 + cQ2n−1 ,
Bn = 2aPn−1 Pn−2 + b(Pn−1 Qn−2 + Pn−2 Qn−1 ) + 2cQn−1 Qn−2 , and
2
Cn = aPn−2 + bPn−2 Qn−2 + cQ2n−2 .
To help with the subsequent computations, let us evaluate
(Rn − x)2 00
|f (Rn )| = |f (Rn ) − f (x)| = (Rn − x)f 0 (x) + f (x)
2
|f 0 (x)| |f 00 (x)|
< + 2
Qn+1 Qn Qn+1 Q2n
2|a||x| + |b| |a|
≤ + 2 .
Qn+1 Qn Qn+1 Q2n

4 Period of the Continued Fraction of n

Let us note that An = Q2n−1 f (Rn−1 ) and Cn = An−1 ; then,


Qn−1 0 |a|
|An | = Q2n−1 |f (Rn−1 )| ≤ |f (x)| + 2
Qn Qn
≤ 2|a||x| + |b| + |a|
and the same goes for Cn . With respect to Bn , we can say that
Bn = Qn−1 Qn−2 (f (Rn−1 ) + f (Rn−2 ) − a(Rn−1 − Rn−2 )2 ), so
|a|
|Bn | ≤ Qn−1 Qn−2 (|f (Rn−1 | + |f (Rn−2 )| + 2 )
Qn−1 Q2n−2
   
Qn−2 1 2
≤ + 1 (2|a||x| + |b|) + + |a|
Qn Q2n−1 Q2n Q2n−1 Q2n−2
3 5
≤ (2|a||x| + |b|) + |a|.
2 2
Then, we have proven that all of An , Bn , and Cn can take a limited num-
ber of values. Eventually, such a triple is bound to reoccur twice, making,
some xk , xl , and xm roots of the same second-degree equation for distinct
k, l, and m. Since a second-degree equation only has two roots, two of those
numbers will have to be equal, say xk = xl . Then, ak+i = al+i for i ≥ 0, q.
e. d.
Actually, there is no need to wait for a triple to reoccur twice, because
xn cannot be both roots of the given equation. The original equation, ax2 +
b
bx + c = 0, has two roots, and the rational − 2a lies between them. Then,
for n > c log |2a| (such that Qn > |2a|), the law of the best approximations
b
says that Rn is closer to x than − 2a (and than the other root). Therefore,
the sign of f (Rn ) only depends on the sign of Rn − x, from a point onward,
and therefore it alternates. Then An and Cn have distinct signs, and, since
xn is positive, the other root of fn must be negative. If the equation has two
roots of different signs, xn must be the positive root. Then, if we repeat the
above reasoning only counting the triples for n > c log 2a, we have proved
the following

Theorem 2.2 If x is the solution of the equation f (x) = ax2 + bx + c = 0


with integer coefficients, the length of the period of the continued fraction
expansion of x cannot exceed (|f 0 (x)| + |a|)2 ( 23 |f 0 (x)| + 52 |a|) + O(log |a|).

If not much can be said in general about the period of a quadratic irra-
tional x (after all, every periodic sequence of integers determines one such
irrational), a lot is √
known about the continuous fraction expansion of irra-
tionals of the form D, for rational D = pq .
Marius Beceanu 5


Theorem 2.3 In the continued √ fraction expansion of D, the remainders
(D)+bn
always take the form xn = cn , where the numbers bn , cn , as well as
the continued fraction digits an can be obtained by means of the following
algorithm: set a0 = bDc, b1 = a0 , c1 = D − a2o , and then compute

D − b2n
 
a0 + bn−1
an−1 = , bn = an−1 cn−1 − bn−1 , cn = .
cn−1 cn−1

√ Pn−1 xn +Pn−2
Proof We already know that D= Qn−1 xn +Qn−2 , or equivalently
√ √ √
−Qn−2 D + Pn−2 (Qn−2 D − Pn−2 )(Qn−1 D + Pn−1 )
xn = √ = 2
Qn−1 D − Pn−1 Pn−1 − DQ2n−1

(−1)n−1 D + DQn−1 Qn−2 − Pn−1 Pn−2
= 2 .
Pn−1 − DQ2n−1

Then, we know precisely the values of bn and cn (which, in case they exist,
must be unique, being rational), namely

bn = (−1)n (Pn−1 Pn−2 − DQn−1 Qn−2 ) and


(2.1)
cn = (−1)n (DQ2n−1 − Pn−1
2 ).

The claims concerning the recurrence relation can be verified direcly. First,
though, we need the following:

Lemma 2.1 If k is a natural number and x a real number, then


   
x bxc
= .
k k

Its proof lies in [1, pp. 295-296]. By using this lemma, one can easily find
that √   √   
D + bn b D + bn c a0 + bn
an = bxn c = = = ,
cn cn cn
while a simple computation shows that
√ √
D + bn−1 1 cn an−1 D + an−1 bn + cn
= xn−1 = an−1 + = an−1 + √ = √
cn−1 xn D + bn D + bn
and equivalently
√ √ √
( D + bn−1 )( D + bn ) = cn−1 (an−1 D + an−1 bn + cn )

6 Period of the Continued Fraction of n


whence we get (since D is irrational) that

bn−1 + bn = cn−1 an−1

and

D + bn−1 bn = cn−1 an−1 bn + cn−1 cn ⇔


⇔ D + bn (bn−1 − cn−1 an−1 ) = bn + cn−1 cn ⇔ D − b2n = cn−1 cn .

Then, the first terms of the sequences are easy to find: x1 = √ 1 =


√ D−a0
D+a0
D−a20
. So b1 = a0 and c1 = D − a20 , q. e. d.

Theorem
√ √ and satisfy √ D − bn <
2.4 The numbers bn and cn are positive
cn < D + bn . Furthermore, we have that bn < D and cn < 2 D.

Proof First, we are going to prove by induction that



D − bn
(2.2) 0< < 1.
cn
Indeed, for n = 1

D − a0 √
0< < D − a0 < 1,
D − a20

Suppose this statement is true for a natural number n. It is always true


that

D − bn+1 D − b2n+1 cn cn
= √ =√ =√
cn+1 cn+1 ( D + bn+1 ) D + bn+1 D + an cn − bn
1
= √ ,
D − bn
+ an
cn
√ √
and by the induction hypothesis D−bcn
n
+an > an ≥ 1, whence D−bn+1
cn+1 <1
as well. Thus, the proof
√ is complete.
We know that D+b cn
n
= xn > 1. By adding this to inequality (2.2)
√ √
we obtain that 2 cnD > 1, or 0 < cn < 2 D. Then, multiplying by the
Marius Beceanu 7

√ √ √
denominator, D+b cn
n
> 1 implies D + b n > cn , and 0 < D−bn
cn < 1

implies
√ D− √ bn < cn . Finally, combining these two inequalities we get
D − bn < D + bn , so bn > 0. Thus, we have proved, albeit in a different
order, all the promised inequalities, q. e. d.
An immediate consequence is

Corollary 2.1 The continued fraction expansion of D is periodic, with a
period of at most pq, if D = pq .

b̃n
Indeed, in virtue of their representation (2.1), we can write bn = q and
c̃n
cn = q , where b̃n and c̃n are integers. For them, the following relations
√ √ √
hold: 0 < b̃n < pq and pq − b̃n < c̃n < pq + b̃n . Thus, c̃n can take
at most 2b̃n − 1 value for each b̃n , and the number of possible distinct pairs
(b̃n , c̃n ) is no greater than

b pqc
X √
2b̃n − 1 = b pqc2 < pq.
b̃n =1

Whenever that number of consecutive pairs is considered, two must coincide.


Thus xk = xl for some 0 < k l < pq, resulting in a period of length at most
pq.

Theorem 2.5 The period of the continued fraction expansion of D starts
with the second term, that is, ∃p ak = ak+p ∀k > 0. Furthermore,√ if the pe-
riod consists of the p terms a1 , a2 , . . . , ap , then ap = 2b Dc and the sequence
a1 , a2 , . . . , ap−1 is symmetric.

Proof Let us also consider the numbers x0n = D−bcn
n
for n > 0. They obey
the recurrence relation
√ √
0 D − bn + an cn D + bn+1 D − b2n+1 cn+1
xn + an = = = √ =√
cn cn cn ( D − bn+1 ) D − bn+1
1
= 0 .
xn+1
j k
Since x0n < 1, we obtain that an = x0 1 , for n > 0. Then, assume that the
n+1
periodicity starts not at 0, that the smallest n0 for which an = an +p ∀n ≥ n0
is not 1. Since an = an + p ∀n ≥ n0 , it follows that x0n0 = x0n0 +p , and, by
the relation above (if n0 > 0) that an0 −1 = an0 +p−1 , which contradicts our

8 Period of the Continued Fraction of n

assumption about n0 . By this contradiction, we have proved that the period


indeed starts with the second
√ term a1 . √
By conjugation from D = a0 + x1 1 we obtain that − D = a0 − x10 , or
1
√ 1
1

x 0 = a0 + D. This gives us a continued fraction expansion of x 0 as


1 1

1 1
= 2a0 +
x01 1
a1 +
1
a2 +
.. 1
. ap−1 + xn

On the other hand, we know that

1 1 1 1
0 = 0 = ap + x0p = ap + = ap +
x1 xp+1 1 ap−1 + x0p−1
x0p

and by recurrence we obtain

1 1
= ap + .
x01 1
ap−1 +
1
ap−2 +
..
. a1 + x01

Since x01 < 1, both are portions of the continued fraction expansion of x,11 ,
and therefore they must coincide. By identifying the coefficients we obtain
that 2a0 = ap , a1 = ap−1 , · · · , ak = ap−k , q. e. d.

3 Numerical experiments
I tried to find out the relation between n and the size of the period in the

continued fraction expansion of n, in brief l(n). I used for this purpose
the algorithm described in Theorem 2.3, implemented in C, in the program
attached to this paper. I tried to evaluate both the average size of l(n) and
its maximal values.
Table 1 contains the successive peaks of l(n)
√ , for 1 < n < 108 , that is to
n
say the values n for which l(n)
√ > √
n
l(m)
m
for all nonsquare m < n. Apparently,
the ratio gets ever larger, by increasingly smaller increments. However, the
table does not make it clear whether the ratio is bounded from above. One
Marius Beceanu 9

Pb√nc
conclusion that can be drawn from it, though, is that neither k=1 d(n −

k 2 ), nor n log n are good upper bounds for l(n); both are much too large.
The graph below tries to bring an intuitive answer to the question
whether the quantity l(n)
√ is bounded, by considering the peaks of this func-
n
tion as given in Table 1 (and disregarding the precise points where they are
attained).

l(n)
Figure 1: The peaks of √ ,
n
plotted in successive order, for 1 < n < 108 .

Here, the upper line represents the peaks, and the lower one the differ-
ences between consecutive peaks; the x-coordinates of the points are equally
spaced. This picture seems to indicate that the ratio is not bounded.
The subsequent graph (Figure 2) illustrates the evolution of l(n) versus
√ √
n, for 1 < n < 1001. The upper line represents local maxima, while
the lower line represents averages of l(n), both computed on intervals of
√ √
length 1 (k < n < k + 1, k ∈ N). The red line represents k = b nc for

comparison. It is clear that l(n) and n have the same order of magnitude,
on the average.
The next diagram (Figure 3) represents the ratio bl(n)
√ , both in average
nc

and the maximum value for b nc = k, as a function of k. The upper line
represents local maxima and the lower line averages of bl(n)
√ , both taken on
nc

the intervals k < n < k + 1. The red line represents y = 1 for comparison.

It can be clearly seen that the average of bl(n)

nc
for b nc = k is less than k,
while the maximum of this function on the same interval is bigger than k.
Finally, the last graph (4) represents the maximum value of the ra-

10 Period of the Continued Fraction of n

√ √
Figure 2: l(n) plotted against b nc, 1 < n < 1001.

l(n) √ √
Figure 3: √
b nc
plotted versus b nc, 1 < n < 1001.
Marius Beceanu 11

tio, namely maxb√nc=k l(n) k , and the inverse of the ratio’s average value,
k
l(k2 +1)+...+l(k2 +2k)
, versus log log k.
2k

l(n) 2k2
Figure 4: maxb√nc=k k and l(k2 +1)+...+l(k2 +2k)
plotted versus log log k, 3 ≤
k ≤ 10000.

This graph starts at k = 3 in order for log log k to be a positive number.


The red line is y = 1 and is provided for comparison. The vertical coor-
dinates have been divided by 4, while the horizontal have been divided by
log log 104 − log log 3 ∼= 2.13.
Only now it is clear that both curves have linear growth, with the slope of
2k2
l(k2 +1)+...+l(k2 +2k)
being approximately 2.2 and the slope of maxb√nc=k l(n) k
being somewhat lower, probably around 1.3. The following conjecture arises
naturally: Conjecture There exist constants a1 ∼ = 2.2, b1 , c1 , a2 ∼
= 1.3, b2 ,
and c2 , such that for every sufficiently large k

k(a1 log log k + b1 ) ≤ √


max l(n) ≤ k(a1 log log k + c1 )
b nc=k

and
Pk2 +2k
k n=k2 +1 l(n) k
≤ ≤ .
a2 log log k + b2 2k a2 log log k + c2

12 Period of the Continued Fraction of n

√ l(n) Pb√nc √
n l(n) n √
n k=1 d(n − k2 ) n log n
2 1 1.414 0.707 0 1.0
3 2 1.732 1.155 0 1.9
7 4 2.646 1.512 4 5.1
43 10 6.557 1.525 26 24.7
46 12 6.782 1.769 28 26.0
211 26 14.526 1.790 98 77.7
331 34 18.193 1.869 140 105.6
631 48 25.120 1.911 218 162.0
919 60 30.315 1.979 278 206.8
1726 88 41.545 2.118 418 309.7
4846 152 69.613 2.183 820 590.7
7606 194 87.212 2.224 1130 779.4
10399 228 101.975 2.236 1368 943.2
10651 234 103.204 2.267 1438 957.0
10774 238 103.798 2.293 1420 963.8
18379 322 135.569 2.375 2034 1331.1
19231 332 138.676 2.394 2052 1367.9
32971 438 181.579 2.412 2916 1889.0
48799 544 220.905 2.463 3720 2384.8
61051 614 247.085 2.485 4278 2722.7
78439 696 280.070 2.485 5048 3156.4
82471 716 287.178 2.493 5124 3250.9
111094 834 333.308 2.502 6188 3872.4
162094 1016 402.609 2.524 7720 4829.7
187366 1106 432.858 2.555 8460 5255.3
241894 1262 491.827 2.566 9916 6096.8
257371 1318 507.317 2.598 10340 6320.3
289111 1400 537.690 2.604 10964 6761.2
294694 1438 542.857 2.649 11308 6836.6
799621 2383 894.215 2.665 25834 12154.1
969406 2664 984.584 2.706 22740 13571.9
1234531 3030 1111.095 2.727 26544 15584.4
1365079 3196 1168.366 2.735 28240 16505.2
1427911 3308 1194.952 2.768 29026 16934.5
1957099 3898 1398.964 2.786 34808 20266.7
2237134 4212 1495.705 2.816 38004 21868.3
2847079 4784 1687.329 2.835 43964 25076.8
5715319 6892 2390.673 2.883 66394 37195.7
10393111 9352 3223.835 2.901 93342 52086.4
12843814 10442 3583.827 2.914 105148 58661.4
14841766 11226 3852.501 2.914 114260 63616.2
18461899 12542 4296.731 2.919 129960 71889.6
20289091 13358 4504.341 2.966 138224 75788.2
23345326 14348 4831.700 2.970 149824 81974.2
28473454 15876 5336.052 2.975 167880 91590.6
39803611 19002 6309.010 3.012 204556 110404.3
40781911 19396 6386.072 3.037 208528 111907.9

Table 1: Maxima of l(n), 1 < n < 108


Marius Beceanu 13

4 Theoretical results
Though by far worse that the bounds which seem attainable in practice,
these are my results concerning l(n).
Let d(n) denote, in the sequel, the number of positive (integer) divisors
of n.
Theorem 4.1 For every  > 0, there exists C() such that
√ (1+) log D
l(n) < C() + D2 log log D .


Here a bound of the form l(n) = O( n(A + B log log n) is probably attain-
able.
Proof For each pair bn , cn , we have cn cn−1 = D − b2n , or cn |D − b2n . Thus,
the number of possible pairs cannot exceed

b Dc
X
d(D − b2 ).
b=1
log n
(1+)
By [3, Theorem 317], for any  > 0, d(n) < 2 log log n for all sufficiently

large n (n > n0 ()). Then, since the function that bounds d(n) in the
inequality above is increasing, it follows that

b Dc
X
l(D) ≤ d(D − b2 )
b=1
X X
≤ d(D − b2 ) + d(D − b2 )
√ √
1≤b≤b Dc 1≤b≤b Dc
D−b2 ≤n0 () D−b2 >n0 ()
n0 ()
log D−b2
X X (1+)
≤ d(k) + 2 log log D−b2

k=1 1≤b≤b Dc
2
D−b >n0 ()
log D
(1+) log
X
≤ C() + 2 log D

1≤b≤b Dc
2
D−b >n0 ()
√ log D
(1+) log
< C() + D·2 log D .

By using the result in [4], namely that 1≤k<√n d(n−k 2 ) = O( n log3 n),
P
it is possible to improve this result to

l(n) = O( n log3 n).

14 Period of the Continued Fraction of n

Finally, it has been proven in [5], by a different methd involving an


estimate of the number of primitive classes of solutions of x2 − Dy 2 = N ,
that
7 √ √
l(D) ≤ 2 D log D + O( D).

Another
√ method, involving a bound on the size of , the √ fundamental unit
in Z[ D], is employed in [6] to show that l(D) < 3.76 D log D.
√ Observation The period length of the continued fraction expansion of
k 2 + 1, k ∈ N, is always 1, and is 1 only for numbers of that form (see [1,
p. 298]). Indeed,
p 1
k2 + 1 = k + .
1
2k +
.
2k + . .

It follows trivially that the minimum of l(n) is 1 on each interval b nc = k
and is attained at n = k 2 + 1.

Concerning the next theorem, the best possible bound is probably better
k
than the one presented below, probably in the order of a2 +c2 log log k for the
average of l(D) on the interval [k 2 + 1, k 2 + 2k]. Nevertheless, I have not
managed to find the proof for a better bound than the one below.

Theorem 4.2 The average size of l(D) for k 2 < D < (k + 1)2 is no greater
than 74 k + 34 .

D+bn
Proof In order that xn = cn , where xn is a remainder in the continuous
√ .
2 ..c and

fraction
√ decomposition of D, we need to have D − b n n D > bn >
| D − cn | (by Theorem 2.4).
For fixed bn and cn , the number of D such that cn | D −b2n cannot exceed
2k 2
cn + 1, because D − bn takes values in an interval of 2k integers. Then, let
us distinguish two cases: cn ≤ k and cn > k.
In the first case, we have k − cn < bn ≤ k, so the number of possible values
for bn is cn .
In the second case, we have cn − k < bn ≤ k, so the number of possible bn
cannot exceed 2k − cn . Furthermore, since cn > k, the number of multiples
of cn in each interval k 2 +1−b2n , . . . , k 2 +2k −b2n (otherwise said, the number
of D with k 2 < D < (k + 1)2 and cn | D − b2n ) cannot exceed 2.
Marius Beceanu 15

Then, the total number of possible triples is no greater than


2 +2k
kX k 2k
X 2k X
l(D) ≤ ( + 1)cn + 2(2k − cn )
cn
D=k2 +1 cn =1 cn =k+1
k
X
≤ 2k 2 + 3 t
t=1
7 3
= k 2 + k.
2 2
Dividing by 2k in order to obtain the average, we get the desired result, q.
e. d.

Appendix
This is the program that I wrote in order to evaluate the size of l(D).

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int period_length(mint n) {
int a_0, a, b, c, b_0, c_0, result=0;
a_0=sqrt(n*1.0);
b=b_0=a_0;
c=c_0=n-a_0*a_0;
do {
a=(a_0+b)/c;
b=a*c-b;
c=(n-b*b)/c;
result++;
} while ((b!=b_0)||(c!=c_0));
return result;
}

int nodiv(int n) {
int i, j, result=1;
for (i=2; i*i<=n; i++)
if ((n%i)==0) {
j=1;

16 Period of the Continued Fraction of n

while ((n%i)==0) {
j++;
n=n/i;
}
result=result*j;
}
if (n!=1) return result<<1;
return result;
}

int estim(int n) {
int i, result=0, j=sqrt(n*1.0);
for (i=1; i<j; i++)
result+=nodiv(n-i*i);
return result;
}

int main() {
int i, j, i2, imax;
int l, lmax;
double r, r0=0.0, s, lavg;
int beginning_number=9332, end_number=10001;
printf("%d %d\n", beginning_number, end_number);
for (i=beginning_number*beginning_number,
i2=beginning_number, imax=i+(i2<<1)+1;
i2<end_number;
i=imax, i2++, imax+=(i2<<1)+1) {
lavg=0.0;
lmax=0;
for (j=i+1; j<imax; j++) {
l=period_length(j);
if (l>lmax) lmax=l;
s=sqrt(j*1.0);
r=l/s;
lavg+=l*1.0;
if (r>r0) {
r0=r;
fprintf(stderr,
"n=%d l(n)=%d sqrt(n)=%.3f r=%.3f "
"est=%d 2nd est=%.1f\n",
Marius Beceanu 17

j, l, s, r, estim(j), sqrt(j*1.0)*log(j*1.0));
}
}
printf("Square root= %d Maximum= %d Average= %.3f\n",
i2, lmax, lavg/((imax-i-1)*1.0));
}
return 0;
}

In order to compute l(n) for n between 1 and k, the program takes
2 −1
 kX 
O l(n)
n=2

time. According to my best estimates, this does not exceed O(k 3 ), but is
3
probably even lower (probably O logklog k ). The program took almost a day


(23 hours) to run for 1 < n < 104 .
Different C programs were also employed to produce the diagrams in-
cluded in the paper.

References
[1] W. Sierpinski, Elementary Theory of Numbers, Panstwowe
Wydawnictwo Naukowe, Warszawa, 1964.

[2] R. Takloo-Bighash, S. J. Miller, H. Helfgott, F. Spinu, Notes for Prince-


ton Junior Seminar, Fall 2002: Diophantine Analysis and Roth’s The-
orem, Princeton University, 2002.

[3] G. H. Hardy, E. M. Wright, Introduction to the Theory of Numbers,


Oxford, Clarendon Press, 1954.

[4] H. W. Lu, A divisor problem (Chinese.) J. China Univ. Sci. Tech. 10


(1980), 131-132; cf. D. S. Mitrinovic, J. Sandor and B. Crstici, Handbook
of Number Theory, Kluwer Academic Publishers, Dordrecht, 1996, p.
69.

[5] J. H. E. Cohn, The Length of the Period of the Simple Continued Frac-
tion of d1/2 , Pacific Journal of Mathematics, Vol. 71, No. 1, 1977, pp.
21-32.

18 Period of the Continued Fraction of n

[6] R. G. Stanton, C. Sudler, Jr., and H. C. Williams,


√ An Upper Bound for
the period of the Simple Continued Fraction for D, Pacific Journal of
Mathematics , Vol. 67, No. 2, 1976, pp. 525-536.

You might also like