Vous êtes sur la page 1sur 45

An Essay on the Euclidean Algorithm

construction at 11FALL/Euclidextendpnew.tex

Franz Rothe
Department of Mathematics
University of North Carolina at Charlotte
Charlotte, NC 28223
frothe@uncc.edu

October 31, 2013

Contents

1 The Euclidean Algorithm 2


1.1 The Common Euclidean Algorithm . . . . . . . . . . . . . . . . . . . . 3
1.2 The Extended Euclidean Algorithm . . . . . . . . . . . . . . . . . . . 3
1.3 Further Properties of the Extended Algorithm . . . . . . . . . . . . . . 7

2 A More Abstract Construction of the Gcd 10

3 The Chinese Remainder Problem 13


3.1 The Battle problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2 Simultaneous Congruences . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.3 Effective Hand Solution of Simultaneous Congruences . . . . . . . . . . 14
3.4 Solution of the Battle Problem . . . . . . . . . . . . . . . . . . . . . . 18
3.5 Additional Formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.6 Chinese Remainder (Sun-Zes) Theorem . . . . . . . . . . . . . . . . . 23
3.7 Calculator Optimized Solution . . . . . . . . . . . . . . . . . . . . . . 24

4 The Postage Problem 27

5 The Speed of Convergence 29

1
6 Reversing the Extended Euclidean Algorithm 33

7 Descartes Problem 35

References
[1] Stan Wagon, Editors Corner: The Euclidean Algorithm Strikes Again, The American
Mathematical Monthly, 97, Feb. 1990, pp.125-129.
[2] Stan Wagon, A Mathematical Magic Trick, The College Mathematical Journal, 25,
Sept. 1994, pp.325-326.

1 The Euclidean Algorithm


Definition 1.1 (Division with remainder). Given any two integers a and positive
integer b > 0, the quotient q and remainder r are defined as the integers such that

(1.1) a = q b + r and 0 r < b

In that case, we write

(1.2) a : b = q rem r

and

(1.3) ar mod b

Definition 1.2 (Greatest common divisor). The greatest common divisor of two
positive integers a and b is the greatest positive integer that is a divisor of both a and
b. We denote the greatest common divisor of a and b by gcd(a, b).

Definition 1.3 (Least common multiple). The least common multiple of two positive
integers a and b is the positive integer l such that

(a) l is a multiple of both a and b.

(b) If any other integer k is a multiple of both a and b, then k is a multiple of l.

We denote the least common multiple of a and b by lcm (a, b).

Intuitively, the greatest common divisor is the greatest common measure for the
lengths a and b. The least common multiple is the least common period of two simul-
taneous processes with individual periods a and b.

2
1.1 The Common Euclidean Algorithm
Let a, b be positive integers. The greatest common divisor gcd(a, b) can be calculated
by successive divisions with remainders. The algorithm starts with dividing a by b. The
last nonzero remainder is the greatest common divisor.

Example 1.1. Take a = 42, b = 16.

42 : 16 = 2 rem 10
16 : 10 = 1 rem 6
10 : 6 = 1 rem 4
6 : 4 = 1 rem 2
4 : 2 = 2 rem 0

The last nonzero remainder is 2, and hence gcd(42, 16) = 2.

Reason. Let subscript i count the rows. One start with the given numbers as remainders
r0 = a and r1 = b. The i-th row of the scheme is

(1.4) ri1 : ri = qi rem ri+1

where the successive remainders ri and quotients qi satisfy

(ri) ri+1 = ri1 qi ri and 0 ri+1 < ri

The algorithm stops when a zero remainder rm+1 = 0 appears for the first time, say in
row m. The last nonzero remainder is rm . We check that rm is the greatest common
divisor. From the identity

(1.5) gcd(a, b) = gcd(a qb, b) = gcd(b, a qb)

which holds for all integers q, we get inductively

gcd(a, b) = gcd(r0 , r1 )
gcd(a, b) = gcd(ri1 , ri ) = gcd(ri , ri+1 ) for all i = 1, 2 . . . m
gcd(a, b) = gcd(rm , rm+1 ) = rm

Hence the last nonzero remainder rm is the greatest common divisor.

10 Problem 1.1. Find the greatest common divisor gcd(4321, 1234).

1.2 The Extended Euclidean Algorithm


Definition 1.4 (Integer combination). Any number sa + tb with (positive or nega-
tive) integers s, t Z is called an integer combination of a and b.

3
Again, a, b are positive integers. Beyond calculating their greatest common divisor,
the extended Euclidean algorithm yields gcd(a, b) as an integer combination

(*) gcd(a, b) = sa tb

Actually, the convenient smallest solution s, t of equation (*) is calculated by the ex-
tended Euclidean algorithm. Furthermore, (1)m s 0 and (1)m t 0, where m is the
number of steps of the algorithm.
Definition 1.5 (The Extended Euclidean Algorithm). Similar to the common
algorithm, one starts with dividing a by b, followed by successive divisions with re-
mainders. One has to keep track of both the quotients qi and remainders ri . But the
extended algorithm needs two extra columns, which start in row 0 and 1 with the 2 2
unit matrix, whereas the divisions start at row 1 with the calculation of a : b. The
operation to successively produce these two extra columns is
row two above current row plus quotient row one above current row 7
gives current row.
The algorithm stops when a division has zero remainder for the first time. The
greatest common divisor gcd(a, b) is the last nonzero remainder. In the m-th row,
adjacent to the zero remainder rm+1 , appear the numbers sm and tm such that

(*m) (1)m gcd(a, b) = sm a tm b

and hence (*) follows with s = (1)m sm and t = (1)m tm . The optional extra row
m + 1 does not contain a division, only sm+1 and tm+1 are calculated. Because of the
relations
b a
(m+1) sm+1 = , tm+1 =
gcd(a, b) gcd(a, b)
shown in Corollary 1.3 below, we get a convenient check.
Example 1.2. Take a = 42, b = 16.
row 0: 1 0
row 1: 42 : 16 = 2 rem 10 0 1
row 2: 16 : 10 = 1 rem 6 1 2
row 3: 10 : 6 = 1 rem 4 1 3
row 4: 6 : 4 = 1 rem 2 2 5
row m=5: 4 : 2 = 2 rem 0 3 8
row m+1: 8 21

Hence gcd(42, 16) = 2 and 3 42 8 16 = 2 = gcd(42, 16). We get s = 3, t = 8.


These numbers are negative since the number m = 5 of steps of the algorithm is odd in
this example.

4
The optional extra row m + 1 does no longer involve a division step of the ordinary
Euclidean algorithm. The extra calculation of sm+1 and tm+1 is a convenient check.
sm+1 and tm+1 are calculated. Because of the relations
b a
(m+1) sm+1 = , tm+1 =
gcd(a, b) gcd(a, b)
shown in Corollary 1.3 below, we get a convenient check.

Reason for the extended algorithm. Let subscript i count the rows. Starting with the
given numbers as remainders r0 = a and r1 = b, the i-th row of the extended scheme is

(i-extend) ri1 : ri = qi rem ri+1 si t i

The two extra columns start with s0 = 1, s1 = 0 and t0 = 0, t1 = 1. The extended


Euclidean algorithm calculates the successive remainders ri and quotients qi via

(ri) ri+1 = ri1 qi ri and 0 ri+1 < ri

and uses the recursion to get the sequences si and ti :

si+1 = si1 + qi si
(1.6)
ti+1 = ti1 + qi ti

Since we get the same two step recursion

(1)i+1 ri+1 = (1)i1 ri1 + qi (1)i ri

for the alternating remainders (1)i ri , we show inductively

(combine) (1)i ri = si a ti b

to hold for all rows i = 0, 1, . . . m + 1. Indeed equation (combine) holds for i = 0, 1,


and inductively follows for all i, because of formulas (ri) and (1.6). The algorithm stops
when a zero remainder rm+1 = 0 appears for the first time in row m. As explained
above, the last nonzero remainder is the greatest common divisor.

(1.7) rm = gcd(a, b) , rm+1 = 0

The identity (combine) with i = m implies

(1)m rm = sm a tm b

hence formula (*m) holds. The numbers sm , tm show up next to the zero remainder
rm+1 = 0. For odd number m steps s = sm , t = tm are negative, for even m, we get
s = sm , t = tm which are positive.

5
10 Problem 1.2. Express the greatest common divisor gcd(4321, 1234) as integer
combination
(*) gcd(a, b) = sa tb
of these two given integers.
Answer.
row 0: 1 0
row 1: 4231 : 1234 = 3 rem 619 0 1
row 2: 1234 : 619 = 1 rem 615 1 3
row 3: 619 : 615 = 1 rem 4 1 4
(1.8)
row 4: 615 : 4= 153 rem 3 2 7
row 5: 4: 3= 1 rem 1 307 1 075
row m=6: 3: 1= 3 rem 0 309 1 082
row m+1: 1234 4321
Hence gcd(4321, 1234) = 1 and 309 4321 1 082 1234 = 1 = gcd(4321, 1234). We get
s = 309, t = 1 082. These numbers are positive since the number m = 6 of steps of the
algorithm is even.
Remark (Backtracking the old fashioned way ). For completeness I mention the back-
tracking algorithm, which can be used to produce formula (*), too. At first one does
the common Euclidean algorithm, keeping the quotients. But as the price for not plan-
ning ahead, one has to remember the two entire sequences of remainders and quotients.
Going backwards, one uses the divisions of the algorithm in reversed order and calcu-
lates expressions for the greatest common divisor in terms of two successively larger
remainders.
Example 1.3. Get integers s, t such that s42 t16 = gcd(42, 16).
gcd(42, 16) = 2 = 6 4 = 6 (10 6)
= 10 + 2 6 = 10 + 2 [16 10]
= 2 16 3 10 = 2 16 3 [42 2 16]
= 3 42 + 8 16
from which we see one (non unique) solution s = 3, t = 8 of formula (*).
10 Problem 1.3. Use the old fashioned backtracking to express the greatest com-
mon divisor gcd(4321, 1234) as integer combination.
Answer.
gcd(4321, 1234) = 1 = 4 3 = 4 [615 153 4]
= 615 + 154 4 = 615 + 154 [619 615]
= 154 619 155 615 = 154 619 155 [1234 619]
= 155 1234 + 309 619 = 155 1234 + 309 [4321 3 1234]
= 309 4321 1082 1234

6
from which we see one (non unique) solution s = 309, t = 1082. such that s4321
t1234 = gcd(4321, 1234).

1.3 Further Properties of the Extended Algorithm


The extended Euclidean algorithm is of basic importance, and deserves further obser-
vations and Corollaries.

Corollary 1.1. The linear diophantine equation

(*) gcd(a, b) = sa tb

has the set of integer solutions s0 , t0


b a
(1.9) s0 = s + , t0 = t +
gcd(a, b) gcd(a, b)
with arbitrary integer .

Reason. It is easy to check that formula (1.9) gives integer solutions of equation (*).
Conversely, suppose that both s, t and s0 , t0 are solutions of (*):

sa tb = gcd(a, b)
s a t0 b = gcd(a, b)
0

Multiplying the first equation above by t0 , the second one by t and subtracting yields
the first equation below, multiplying the first equation by s0 , the second one by s and
subtracting yields the first equation below. Similarly, we get the second one.

(t0 s ts0 )a = (t0 t) gcd(a, b)


(s0 t + st0 )b = (s0 s) gcd(a, b)

Hence equation (1.9) holds with = st0 s0 t.

Corollary 1.2. The least common multiple of any positive integers a and b is
ab
(1.10) lcm (a, b) =
gcd(a, b)
Proof. We check that the number
ab
(1.11) l :=
gcd(a, b)

on the right hand side satisfies both requirements (a) and (b) from the definition 1.3 of
the least common multiple.

7
b a
(a) The number l is a multiple of both a and b, since l = a gcd(a,b)
= gcd(a,b)
b.

(b) Assume the positive integer k is a multiple of both a and b. We need to check that
k is a multiple of l.

Check of item (b). Since the positive integer k is assumed to be a multiple of both a
and b, there exist integers p and q such that k = aq = bp. The greatest common divisor
satisfies

(*) gcd(a, b) = sa tb

from the extended Euclidean algorithm. Hence

gcd(a, b) k = sa k tb k = sa bp tb aq = (a b) (sp tq)


ab
k= (sp tq) = l (sp tq)
gcd(a, b)
Hence k is a multiple of l, as to be shown.
Proposition 1.1 (The combination and determinant identities).

(combine) (1)i ri = si a ti b for i = 0, 1 . . . m + 1


i
(det) si ti+1 si+1 ti = (1)
(det-r) ri ti+1 + ri+1 ti = a for i = 0, 1 . . . m

10 Problem 1.4. Show the determinant identity (det) by induction for i =


0, 1, . . . m. Use induction step i 1 7 i.
Answer. s0 t1 s1 t0 = 1 1 0 0 = 1 gives the start. Here is the induction step
i 1 7 i:

si ti+1 si+1 ti = si [ti1 + qi ti ] [si1 + qi si ]ti = si ti1 si1 ti


= [si1 ti si ti1 ] = (1)i1 = (1)i

Too, we get formula (det-r), since

ri ti+1 + ri+1 ti = (1)i [si a ti b]ti+1 + (1)i+1 [si+1 a ti+1 b]ti


= (1)i a[si ti+1 si+1 ti ] = a

Corollary 1.3. One can take the calculation of the sequences si and ti one step further
up to i = m + 1 and get
b a
(m+1) sm+1 = , tm+1 =
gcd(a, b) gcd(a, b)

8
Reason for Corollary 1.3. We set up a linear system to calculate the extra values sm+1
and tm+1 . To this end we use formula (combine) for i = m + 1, and the determinant
identity (det) with i = m.
tm sm+1 sm tm+1 = (1)m+1
(sys)
a sm+1 b tm+1 = 0
The determinant of system (sys) is
= tm b + sm a = (1)m gcd(a, b) 6= 0
Hence system (sys) has a unique solution, to be obtained by Cramers rule. It turns out
to be (m+1).
Remark. Here is a direct calculation to check (m+1):
b = (1)m+1 [(bsm+1 ) tm sm (btm+1 )] = (1)m+1 [(bsm+1 ) tm sm (asm+1 )]
= (1)m+1 [btm asm ] sm+1 = gcd(a, b) sm+1

a = (1)m+1 [(asm+1 ) tm sm (atm+1 )] = (1)m+1 [(btm+1 ) tm sm (atm+1 )]


= (1)m+1 [btm asm ] tm+1 = gcd(a, b) tm+1
Corollary 1.4. Assume a 6= b. The solution s, t of equation (*) constructed by the
extended Euclidean algorithm is the unique solution of (*) satisfying
b a
(**) |s| and |t|
2 gcd(a, b) 2 gcd(a, b)
Reason. The assumption a 6= b implies that the last quotient qm 2. Hence corollary 1.3
and formula (1.6) with i = m imply
b
= sm+1 = sm1 + qm sm 2|s|
gcd(a, b)
a
= tm+1 = tm1 + qm tm 2|t|
gcd(a, b)
for the solution s, t of (*) constructed above. Hence s, t satisfy (**).
10 Problem 1.5. Prove uniqueness for the solutions of (*) and (**).
Answer. Suppose that s, t and s0 , t0 are two different solutions of formulas (*) and (**).
Both
b b b
|s0 s| = || and |s0 s| |s| + |s0 | 2
gcd(a, b) gcd(a, b) 2 gcd(a, b)
by (1.9) from Corollary 1, and formula (**). Since s 6= s0 , both inequalities together
imply |s0 s| = |s| + |s0 | and hence s = s0 = 2 gcd(a,b)
b
. Similarly one gets t = t0 =
a
2 gcd(a,b) . Now formula (*) implies
gcd(a, b) = sa tb = (s0 a t0 b) = gcd(a, b) = 0
which is impossible.

9
2 A More Abstract Construction of the Gcd
Definition 2.1 (Integer combination). Any number sa + tb with (positive or nega-
tive) integers s, t Z is called an integer combination of a and b.

Proposition 2.1 (The gcd as integer combination). The greatest common divisor
of any two positive integers a and b is the smallest positive integer combination of a and
b.

Proof of Proposition 2.1. Let a, b N be fixed. We define

x := min{sa + tb > 0 : s, t Z}

and check the following three claims:

(i) If h | a and h | b, then h | sa + tb


holds for any (positive or negative) integers s, t Z.

(ii) gcd(a, b) | x.

(iii) x | a and x | b

Using (ii) and (iii), it is now easy to show that actually gcd(a, b) = x. Indeed item
(ii) implies gcd(a, b) x. On the other hand, item (iii) implies that x is indeed a
common divisor of a and b, and hence x gcd(a, b). Both inequalities together imply
x = gcd(a, b), as to be shown.

10 Problem 2.1. Give the reason for the three items (i)(ii)(iii).

Reason for item (i). By the assumptions h | a and h | b, there exist integers p and q
such that a = ph and b = qh. Hence

sa + tb = sph + tqh = (sp + tq)h

Hence h is a divisor of the integer combination sp + tq.


Reason for item (ii). For any integers s, t Z, and any common divisor of a and b, we
know that
h | sa + tb
Hence this holds for the greatest common divisor gcd(a, b) and the smallest positive
integer combination x, too. Hence gcd(a, b) | x.
Reason for item (iii). It is enough to check that x divides a. To this end, we divide
a x with remainder and get
a = qx + r

10
with q, r Z and remainder 0 r < x. Hence

r = a qx = a q(sa + tb) = (1 qs)a + (qt)b

which shows that the remainder is an integer combination of a and b. Since r < x and
x is the smallest positive integer combination, we conclude r = 0. Hence x divides a
without remainder, as to be shown.
Proposition 2.2 (Characterization of the gcd via divisibility). Assume that a
and b are not both zero. The greatest common divisor of any such integers a and b, is
the integer g such that
(a) g | a and g | b.

(b) If h | a and h | b, then h | g.


Properties (a) and (b) determine the greatest common divisor uniquely, up to its sign.
Proof of Proposition 2.2. Let a, b Z be fixed, not both zero. We check that (a) and (b)
hold for g := gcd(|a|, |b|). One gets (a) immediately from the definition of the greatest
common divisor.
Check of (b). Let h be any common divisor of a and b. Obviously, |h| be a common
divisor of |a| and |b|. Hence |h| divides any integer combination s|a| + t|b|. As we know
from Proposition 2.1, the greatest common divisor is an integer combination, too. Hence
|h| divides gcd(|a|, |b|), and one gets (b).
To check uniqueness, suppose that both g and g 0 are greatest common divisors of a
and b. By item (a), g 0 divides both a and b. Now item (b) with h := g 0 implies g 0 | g.
Similarly, we g | g 0 . Hence |g 0 | |g| |g 0 |, and |g 0 | = |g| and finally g 0 = g, as to be
shown.
Proposition 2.3. If two relative prime numbers a and b both divide the number c, then
their product ab divides c.
Standard proof . By the assumption, there exist integers p and q such that c = ap = bq.
By the extended Euclidean algorithm, there exist integers s, t such that

1 = sa + tb

We multiply both sides by c and use c = bq and c = ap at the appropriate places:

c = csa + ctb = bqsa + aptb = ab(qs + pt)

Hence ab divides c, as to be shown.


Proposition 2.4 (The Euclidean Property). If a number c divides the product ab
and gcd(c, a) = 1, then c divides b.

11
Standard proof . By the extended Euclidean algorithm, there exist integers s, t such that
1 = sa + tc
Multiplying both sides by b, and using ab = qc yields
b = sab + tcb = sqc + tcb = (sq + tb)c
Hence c divides b, as to be shown.
Theorem 2.1 (Least common multiple). The least common multiple of two positive
integers a and b is the smallest positive integer that is a multiple of both a and b.
Proof. Let l be the positive integer such that
(a) a | l and b | l.
(b) If a | k and b | k, and k 0, then l k.
10 Problem 2.2. Prove that the two requirements (a) and (b) determine the
natural number l uniquely.
Replace k in requirement (b) by the
ab
l :=
gcd(a, b)
Since the condition imposed inside (b) does hold, we conclude that
ll
The requirement (b) is weaker than the divisibility requirement (b) which we have
imposed in the original definition 1.3and checked to hold for l.
Next we put
k := gcd(l, ab)
into requirement (b). Since the condition imposed inside (b) does hold, we conclude
that
l gcd(l, ab)
Hence l is a divisor of ab, and
ab
q :=
l
is an integer. Since q is a divisor of both a and b, we see that q is a divisor of gcd(a, b).
Hence
ab
q= gcd(a, b)
l
ab
l= l
gcd(a, b)

12
Since we have already shown l l, we conclude l = l.
We have shown in corollary 1.2 above that l is the least common multiple, according
to the original definition 1.3. Since l = l, both definitions of the least common multiple
are equivalentusing either requirement (b) or requirement (b).

3 The Chinese Remainder Problem


3.1 The Battle problem
The following example is taken from thirteenth-century Chinese literature:

A military unit won a battle. At 5 a.m., immediately following the victory,


the commander sent three express messengers to the capital. Oddly, they
arrived at different times to announce the news.

Messenger Presto arrived several days ago, at 5 p.m.;


messenger Quickest a few days later at 2 p.m.; and
messenger Run-fast arrived this morning at 9 a.m.

If messenger P ran at a pace of 300 li/day, messenger Q at a pace of 240


li/day, messenger R at a pace of 180 li/dayfind the distance, measured
in li, from the battle site to the capital, and figure out how many days
ago the battle was won.

10 Problem 3.1. Let the distance from the capital to the battle site be x li.
Assume the messengers P,Q and R ran p, q and r entire days plus a few hours more.
How many miles did each of the messengers cover during the his last extra hours, beyond
the many entire days he kept running? Set up the equations relating x, p, q, r and a
system of three simultaneous congruences for x.

Answer. The messengers ran 12, 9 and 3 more hours than entire days. In these extra
hours they could cover 150, 90 and 30 li, respectively. Hence

(x) x = 150 + 300p = 90 + 240q = 30 + 180r


(P) x 150 mod 300
(Q) x 90 mod 240
(R) x 30 mod 180

3.2 Simultaneous Congruences


The solution of simultaneous congruences leads to the Chinese remainder theorem.

13
Theorem 3.1 (Chinese Remainder Theorem). Simultaneous congruences

x u mod a
(ch)
x v mod b

have either a solution determined uniquely modulo the least common multiple, or no
solution. They are solvable if and only if the difference u v is divisible by gcd(a, b).

Necessary for solvability is that gcd(a, b) divides u v. Suppose that the system (ch)
has the solution x. The two congruences imply that both x u and x v are di-
visible by the greatest common multiple gcd(a, b). Hence their difference needs to be
divisible by u v.

The solution is only defined modulo the least common multiple. Let x be a solution of
the system (ch). Then for any integer , the number x + lcm (a, b) is a solution
of (ch), too.

The solution is unique modulo the least common multiple. Suppose the system of simul-
taneous congruences (ch) has two solutions x and x0 . In that situation, both numbers
a and b are divisors of the difference x x0 . In other words, the difference x x0 is a
multiple of both numbers a and b, and hence x x0 is a multiple of the least common
multiple lcm (a, b). In other words

x x0 mod lcm (a, b)

Now I give a rather effective solution of the simultaneous congruences (ch), good for
hand calculations. From that algorithm, it is clear that the greatest common divisor
dividing u v is a sufficient condition for solvability of (ch). After an example, the
justification is elaborated to yield some useful general formulas. Finally a ruthlessly
optimized solution suitable to be programmed on TI 85 is presented.

3.3 Effective Hand Solution of Simultaneous Congruences


An exceptionally easy case are simultaneous congruences (ch) for which the right-hand
sides u = v are equal.
10 Problem 3.2. Use the Euclidean algorithm to find gcd(99, 6).
Answer.
99 : 6 = 16 rem 3
6 : 3 = 2 rem 0
The greatest common divisor is now gcd(99, 6) = 3, which is the last nonzero re-
mainder.

14
10 Problem 3.3. Find the least common multiple lcm (99, 6).
Answer.
20 7
lcm (99, 6) = = 198
gcd(99, 6)
It is now easy to solve the given simultaneous congruences.
x4 mod 99
x4 mod 6
Why is this particularly easy?
Answer. The remainder is the same in both congruences. They simply tell that x 4 is
divisible by both 99 and 6. Hence x 4 is divisible by the least common multiple 198.
In other words
x 4 mod 198

To solve the simultaneous congruences


x u mod a
(ch)
x v mod b
in the general case, we shall reduce them to the special case with u = v. To this end, we
need once more the extended Euclidean algorithm. We set up the extended algorithm
to get the greatest common divisor gcd(a, b), and include two extra columns for the
sequences si and ti . These two extra columns start in row zeroone row above the
simple Euclidean algorithm with a 2 2 unit matrix:
s0 = 1, t0 = 0, s1 = 0, t1 = 1
As results of the extended Euclidean algorithm, one gets items (a) and (b).
(a) the greatest common divisor gcd(a, b) as the last nonzero remainder.
(b) in the m-th row of the two extra columns appear sm and tm . The integers s =
(1)m sm and t = (1)m tm satisfy
(*) gcd(a, b) = sa tb

(c) In the next step we decide existence or nonexistence of a solution of (ch). To this
end we calculate
vu
(d) d :=
gcd(a, b)
If d turns out not to be an integer, the greatest common divisor gcd(a, b) does
not divide the difference u v, and the simultaneous congruences (ch) have no
solution. If d is an integer, we go on to get the solution of (ch).

15
(d) We convert the given simultaneous congruences (ch) into an equivalent system
x u + pa mod a
(ch)
x v + qb mod b
with equal right-hand sides u + pa = v + qb. To determine p and q, we multiply
both sides of formula (*) by d. Next one puts u and a on the left hand, but v and
b on the right hand side.

(ds) a (dt) b = d gcd(a, b)


(ds) a (dt) b = v u
(wequal) u + (ds) a = v + (dt) b

In this identity, it is important to keep the factors a and b separate, therefore I


have underlined those two given numbers.
(e) We have found
p := ds and q := dt
Both sides of equation (wequal) are equal to the same number

w := u + pa = v + qb

Better check whether both sides of equation (wequal) are equal. One needs to get
w = w : both sides are equal! The number w is a solution of the system (ch).
Indeed, this system is equivalent to the equations
x u + pa mod a
(ch)
x v + qb mod b
which have two equal right-hand sides w := u + pa = v + qb. We get the solution

x w mod lcm (a, b)

(f ) The solution is only determined modulo the least common multiple of a and b, which
we get via the formula
ab
(1.10) lcm (a, b) =
gcd(a, b)

(g) Finally, one wants to state the result in terms of the reduced remainder

(w) w w mod lcm (a, b) and 0 w < lcm (a, b)

The solution of the simultaneous congruences (ch) is now

(solution) xw mod lcm (a, b)

16
It is uniquely determined modulo the least common multiple lcm (a, b).

10 Problem 3.4. Solve the simultaneous congruences

x1 mod 42
(chexample)
x3 mod 16

by direct hand calculation.

Example 3.1 (Direct hand solution). Do the extended Euclidean algorithm, keeping
the quotients and two extension columns.

1 0
42 : 16 = 2 rem 10 0 1
16 : 10 = 1 rem 6 1 2
10 : 6 = 1 rem 4 1 3
6 : 4 = 1 rem 2 2 5
2 : 1 = 2 rem 0 3 8
8 21

(a) The greatest common divisor is gcd(42, 16) = 2.


(b) With s = 3, t = 8, the greatest common divisor is the integer combination

(*) (3) 42 + 8 16 = 2

(c) To test whether the problem has a solution, divide


vu 31
(d) d= = =1
gcd(a, b) 2

Because this turns out to be an integer, the simultaneous congruences (chexample) are
solvable.
(d) The key step to calculate the solution is to multiply both sides of formula (*) by
d = 1. This is really easy!

(ds) a (dt) b = d gcd(a, b) =vu


(3) 42 + 8 16 = 2 =31

We then put u, and the multiple of a on the left-hand side. But v, and the multiple of b
from the second equation on the right-hand side. At this point, it is important to keep
the factors 42 and 16 separate, therefore I have underlined those two given numbers.

(wequal) 1 3 42 = 3 8 16
165 = 165

17
(e) Both sides of the last line are equal to the same number 165, which is a solution
of (chexample). Better check that both sides are equal!
(f ) The least common multiple is
42 16
lcm (42, 16) = = 336
2
(g) Finally, because the solution of (chexample) is only uniquely determined modulo
the least common multiple 336, one wants to state it in terms of the reduced remainder
which is uniquely specified by

(w) w w mod 336 and 0 w < 336

which is w = 165+336 = 211. The solution of the simultaneous congruences (chexample)


is now
x 211 mod 336

3.4 Solution of the Battle Problem


We now can solve the battle problem. Let the distance from the capital to the battle
site be x li. The messengers P,Q and R ran p, q and r entire days plus 12, 9 and 4 hours
more. In these extra hours they could cover 150, 90 and 30 li, respectively. As already
seen in problem 3.1, we get the system of simultaneous congruences

(x) x = 150 + 300p = 90 + 240q = 30 + 180r


(P) x 150 mod 300
(Q) x 90 mod 240
(R) x 30 mod 180

10 Problem 3.5 (The battle problem). Solve the simultaneous congruences and
the equation x = 150 + 300p = 90 + 240q = 30 + 180r. How far away from the capital
was the battle site? We assume that China is so small that only the smallest positive
solution can be right. How many entire days did each of the messengers run?
10 Problem 3.6. Begin by solving the first two congruences

x 150 mod 300


(PQ)
x 90 mod 240
Answer. The extended Euclidean algorithm:
1 0
300 : 240 = 1 rem 60 0 1
240 : 60 = 4 rem 0 1 1
4 5

18
(a) The greatest common divisor is gcd(300, 240) = 60.
(b) With s = 1, t = 1, the greatest common divisor is the integer combination
(*) 1 300 1 240 = 60

(c) To test whether the problem has a solution, divide


vu 90 150
(3.1) d= = = 1
gcd(a, b) 60
Because this turns out to be an integer, the simultaneous congruences (PQ) are
solvable.
(d) The key step to calculate the solution is to multiply both sides of formula (*) by
d = 1.
(ds) a (dt) b = d gcd(a, b) =vu
(1) 300 + 240 = 60 = 90 150
Keep the factors 300 and 240 separate, therefore they are underlined. Next one
puts u = 150 and 300 on the left hand, but v = 90 and 240 on the right hand side.
150 1 300 = 90 1 240
150 = 150

(e) Both sides of the last line are equal to the same number 150, which is a solution
of (PQ). Better check that both sides are equal!
(f ) The least common multiple is
300 240
lcm (300, 240) = = 1200
60
(g) Finally, because the solution of (PQ) is only uniquely determined modulo the least
common multiple 1200, one wants state it in terms of the reduced remainder
(w) w w mod 1200 and 0 w < 1200
which is w = 150 + 1200 = 1050. The solution of the simultaneous congruences
(ch2) is now
x 1050 mod 1200
10 Problem 3.7. To solve all three simultaneous congruences, we combine the
solution of the first two with the third one. Solve the resulting two congruences
x 1050 mod 1200
([PQ]R)
x 30 mod 180

19
Answer. The extended Euclidean algorithm:

1 0
1200 : 180 = 6 rem 120 0 1
180 : 120 = 1 rem 60 1 6
120 : 60 = 2 rem 0 1 7
3 20

(a) The greatest common divisor is gcd(1200, 180) = 60.

(b) With s = 1, t = 7, the greatest common divisor is the integer combination

(*) 60 = (1) 1200 + 7 180

(c) To test whether the problem has a solution, divide


vu 1050 30
(d) d= = = 17
gcd(a, b) 60

Because this turns out to be an integer, the simultaneous congruences ([PQ]R) are
solvable.

d) The key step to calculate the solution is to multiply both sides of formula (*) by
d = 17.

(ds) a (dt) b = d gcd(a, b) =vu


(17) 1200 + 119 180 = 1020 = 1050 30

Keep the factors 1200 and 180 separate, therefore they are underlined. Next one
puts u = 1050 and 1200 on the left hand, but v = 30 and 180 on the right hand
side.

1050 + 17 1200 = 30 + 119 180


21 450 = 21 450

(e) Both sides of the last line are equal to the same number 21 450, which is a solution
of ([PQ]R). Better check that both sides are equal!

(f ) The least common multiple is


1200 180
lcm (1200, 180) = = 3600
60

20
(g) Finally, because the solution of ([PQ]R) is only uniquely determined modulo the
least common multiple 3600, one wants state it in terms of the reduced remainder

(w) w w mod 3600 and 0 w < 3600

which is w = 21 450 5 3600 = 3 450. The solution of the simultaneous congru-


ences (ch3) is now
x 3 450 mod 3600

10 Problem 3.8. Complete the solution of the battle problem. How far away
from the capital was the battle site? We assume that China is so small that only the
smallest positive solution can be right. How many entire days did each of the messengers
run?

Answer. x = 3 450 is the smallest positive solution, which is the distance from the battle
field to the capital. This value for x yields p, q and r, too.
3 450 150
Messenger P ran p = = 11 entire days and 12 hours.
300
3 450 90
Messenger Q ran q = = 14 entire days and 9 hours.
240
3 450 30
Messenger R ran r = = 19 entire days and 4 hours.
180
The battle was won 19 days before the arrival of the last messenger.

3.5 Additional Formulas


Proposition 3.1. If it exists, the solution of the simultaneous congruences (ch) is given
by either formulas
vu
(chs) x = u + pa = u + sa
gcd(a, b)
vu
(cht) x = v + qb = v + tb
gcd(a, b)
sva tub
(chresult) x=
gcd(a, b)

with s, t satisfying

(*) gcd(a, b) = sa tb

from the extended Euclidean algorithm.

21
Remark. If equation (ch) is solvable, these formulas give the solution. Different choices
of s, t lead to the same solution modulo the least common multiple lcm (a, b). But in
the case that equation (ch) is not solvable, these formulas give wrong integral values,
which still depend on the particular choice of s, t.
Reason. By definition, the system (ch) means that there exist integers p and q such that

x u + pa mod a
(ch)
x v + qb mod b

Hence we need to find p and q such that

(3.2) u v = pa + qb

It is now straightforward to compare this relation with

(*) gcd(a, b) = sa tb

from the extended Euclidean algorithm. One needs to multiply both sides of the latter
equation (*) by the integer
uv
d =
gcd(a, b)
and get a non-unique solution of equation (3.2):
vu vu
p = ds = s , q = dt = t
gcd(a, b) gcd(a, b)

Plugging this result into equation (ch) yields alternatively to the two expressions (chs)
and (cht). As already clear from (ch) above, both have to turn out to be the same result.
Putting the fractions on a common denominators yields both times formula (chresult).

10 Problem 3.9. Check that both expressions (chs) and (cht) are equal to (chresult).

Answer.
vu u gcd(a, b) + sa(v u)
u + sa =
gcd(a, b) gcd(a, b)
u(sa tb) + sa(v u)
=
gcd(a, b)
sva tub
=
gcd(a, b)

22
A similar calculation starts with the second expression
vu v gcd(a, b) + tb(v u)
v + tb =
gcd(a, b) gcd(a, b)
v(sa tb) + tb(v u)
=
gcd(a, b)
sva tub
=
gcd(a, b)
and yields indeed the same result.
10 Problem 3.10. Solve the battle problem combining the congruences in the
order QR and then [QR] P. Solve the battle problem combining the congruences in the
order PR and then [PR] Q.

3.6 Chinese Remainder (Sun-Zes) Theorem


We now assume a and b to be relatively prime positive integers. The solution of the
simultaneous congruences:
x u (mod a)
(ch)
x v (mod b)
defines a (total) function f : Za Zb 7 Zab since we know the simultaneous congruences
to be solvable for any right-hand side (u, v) Za Zb , and the solution to be uniquely
determined modulo ab.
The inverse function x 7 f 1 (x) = (u, v) is obtained by reducing any x Zab to the
remainders u Za and v Zb ; as one naturally has to do when checking the solution
of the Chinese remainder problem. Since the reduced remainders are unique, we see
that f 1 is a function, too, and hence the function f is injective. Moreover, the value
x Zab can be chose arbitrarily and f 1 is a well-defined (total) function, and hence f
is surjective.
Suns-Zes result was obtained before 850, the statement below was obtained by
Chin-Chin Shao about 1250.
Theorem 3.2 (Chinese Remainder Theorem). Assume a and b are relatively prime
positive integers. Let s, t be integers satisfying
(*) gcd(a, b) = sa tb
from the extended Euclidean algorithm.
The function
f : Za Zb 7 Zab
f (u, v) = v sa u tb

23
is a bijection which yields the solution of the Chinese remainder problem (ch). Its
inverse x 7 f 1 (x) = (u, v) is obtained by reducing x Zab to the remainders u Za
and v Zb .
Let U(Zm ) be the group of units in the ring Zm . Clearly, this group can be repre-
sented by the congruence classes (a mod m) for which gcd(a, m) = 1 holds. Hence the
order of this group
| U(Zm ) | = (m)
is the Euler totient function.
Moreover, consider for the Chinese remainder problem problem (ch) the case that
gcd(u, a) = gcd(v, b) = 1, and gcd(a, b) = 1 as was assumed before. Under these
assumptions, gcd(f (u, v), ab) = 1 holds for the solution of problem (ch). The converse
is true, too: gcd(f (u, v), ab) = 1 implies gcd(u, a) = gcd(v, b) = 1. Hence we get an
interesting result about the structure of the group U(Zab ):
Corollary 3.1. For any relatively prime a and b we have a group isomorphism, and
hence the Euler totient function is multiplicative.
U(Za ) U(Zb ) ' U(Zab )
(ab) = (a)(b)

3.7 Calculator Optimized Solution


The notation used in this paragraph is a bid different from above. One sets up the
Euclidean algorithm to get the greatest common divisor gcd(a, b). From the extended
Euclidean algorithm, we need only one extra column for the sequence si = (1)i si . The
extra column starts in row one and two with s1 = 0 and s2 = 1. The recursion is
si+1 = si1 qi si , leading to alternating signs. One gets the greatest common divisor
gcd(a, b) as the last nonzero remainder, and the integer s = (1)m sm = sm in the extra
column.
To determine whether the congruences (ch) are solvable, one checks whether gcd(a, b)
divides the difference u v. To this end, one calculates
uv
(3.3) d :=
gcd(a, b)
The congruences congruences (ch) are solvable if and only if d is an integer. In this case,
one goes on and calculates
b
(3.4) h :=
gcd(a, b)
(3.5) lcm (a, b) := ah
(3.6) p := ds mod h

(3.7) w := u pa
(3.8) w = w mod lcm (a, b)

24
The solution of the simultaneous congruence modulo the least common multiple, with
reduced remainder is

(3.9) xw mod lcm (a, b)

10 Problem 3.11. Following the procedure above, solve the simultaneous con-
gruences

(3.10) x1 mod 42
(3.11) x3 mod 16

Get a congruence modulo the least common multiple, with reduced remainder.

Express solution. Do the extended Euclidean algorithm, keep the quotients, use one
extension column, with alternating signs.

42 : 16 = 2 rem 10 0
16 : 10 = 1 rem 6 1
10 : 6 = 1 rem 4 1
(3.12)
6 : 4 = 1 rem 2 2
2 : 1 = 2 rem 0 3
8

One gets gcd(42, 16) = 2 and s = 3. (It is easy to check that t = 8, but we do not
need it.) Are the congruences solvable? To check calculate
uv 13
(3.13) d := = = 1
gcd(a, b) 2

because this is an integer, the congruences are solvable. So go on and calculate


b 16
(3.14) h := = =8
gcd(a, b) 2
(3.15) lcm (a, b) := ah = 42 8 = 336
(3.16) p := ds mod h = (1) (3) mod 8 = 3

(3.17) w := u pa = 1 3 42 = 125
(3.18) w := w + lcm (a, b) = 125 + 336 = 211

Result

(3.19) x 211 mod 336

25
Definition 3.1 (Program for the TI84). Three successive remainders ri are
X,Y,Z
Three successive terms si are
R,S,G
In the end, one should have
rM = Y , sM = S, sM +1 = G.
Prompt A,B
Lbl 0
Prompt U,V
A -> Y: B -> Z
1 -> S: 0 -> G: 0 -> M
Lbl 1
If Z = 0:Goto 2
Y -> X: Z -> Y
S -> R: G -> S
int(X/Y) -> Q
X-QY -> Z: R-QS -> G: M+1 -> M
Goto 1
Lbl 2
Disp{Y,M}
B/Y -> H: AH -> L
(U-V)/Y -> D
DS -> P
P-int(P/H)H -> P
U-PA -> W
W-int(W/L)L -> W
Lbl 3
{D,W-U-int((W-U)/A)A,W-V-int((W-V)/B)B} -> L_1
Disp L_1
Disp {W,L}
The output of the program consists of these three lists:
{Y,M}
{D,W-U-int((W-U)/A)A,W-V-int((W-V)/B)B}
if and only if the congruences are solvable, and two check numbers that are 0, 0 if
and only if the congruences solved correctly;
{W,L}
10 Problem 3.12. Check the solution of the battle problem with the program
above.

26
4 The Postage Problem
Stamps are available only in two denominations of integer values a and b. For which
values can a letter get the postage value N by using only these two denominations?
This problem leads to the equation

(1) N = xa + yb

with nonnegative integers x, y 0.


Proposition 4.1 (The Postage Proposition). We assume that a > b > 1 and
furthermore that a and b are relatively prime.
(i) All postage values N (a 1)(b 1) can be done using only the two relatively
prime denominations a and b.
(ii) Exactly half of the smaller values N = 0, 1, . . . , ab a b can be done, and the
other half cannot be done. Hence there are exactly (a1)(b1)
2
values that cannot be posted.
(iii) A value 0 N abab can be posted if and only if the value N 0 = ababN
cannot be posted. Especially, the values 0 and ab a b 1 can be posted, but the values
ab a b and 1 cannot be posted.
Reason. At first we allow the integers x, y to be negative or positive. Under this less
restrictive assumption, one can solve the equation

(1) N = xa + yb

for all integers N positive or negative. Now we can use the extended Euclidean algorithm
to get all solutions:
Answer.

(pm) x = N s + b , y = N t a

with arbitrary integer and s, t such that 1 = sa bt, as stated in the extended
Euclidean algorithm.
The postage problem requires a solution of equation (1) with the additional restric-
tions x 0 and y 0. The possible choices of the number x are an arithmetic sequence
with difference b. To increase y, one wants to chose x 0 as small as possible. In that
case 0 x b 1. Once x in that interval is fixed, formula (1) determines the integer
y uniquely. The question is whether y come out as nonnegative or negative. (Similarly,
we could choose y in the interval 0 y a 1, and then check whether x comes out
as nonnegative.)
Now we give the reason for (i). Supposing (1) cannot be solved with x 0 and
y 0, we show that N < (a 1)(b 1).
Assume that equation (1) cannot be solved with x 0 and y 0. As explained
above, one can still solve (1) with x or y a negative integer. Furthermore, we can assume
0 x b 1 by fixing the choice of x in the arithmetic sequence of difference b.

27
Since equation (1) cannot be solved with x 0 and y 0, this reasoning needs to
lead to a solution of (1) with 0 x b 1 and y < 0. But these two inequalities imply

N = xa + yb (b 1)a b = (a 1)(b 1) 1

Thus nonexistence of a solution of the postage problem implies N < (a1)(b1). Hence,
the contrapositive statement confirms item (i): If N (a 1)(b 1), equation (1) can
be solved with x 0 and y 0.
Next we confirm item (ii). Suppose that 0 N ab a b, and (1) can still be
solved with x 0 and y 0. We define

(2) x0 = 1 x , y 0 = a 1 y , N 0 = ab a b N

It is easy to check that N = xa + by implies

(2) N 0 = x0 a + y 0 b = (x0 + b)a + (y 0 a)b

Because of x0 < 0, y 0 < a and x0 + b < b, y 0 a < 0, we see that the integer N 0 is not
an nonnegative integer combination of a and b. Hence the postage value N 0 cannot be
done.
The converse holds, too: If the postage value 0 N 0 ab a b cannot be done,
then the postage value N = ab a b N 0 can be done.
Indeed, assuming that value N 0 cannot be posted means that (2) holds with x0 <
0
0, y < a. With x, y and N from relations (2), we get N = xa + by with x 0 and y 0.
Hence the postage value N = ab a b N 0 can be done.

10 Problem 4.1. Find all values N that cannot be posted with just the two
denominations a = 7, b = 3. How many are there? Use the postage proposition to
conform that you got all cases.

Answer. The six values 1, 2, 4, 5, 8, 11 cannot be posted with these two denominations.
Because (a1)(b1)
2
= 6, the postage proposition tells we got all cases that cannot be
posted.

10 Problem 4.2. Check once more directly that the value N = (a 1)(b 1) 1
cannot be posted.

Answer. We can find two solutions of (1):

(a 1)(b 1) 1 = (b 1) a 1 b
(a 1)(b 1) 1 = 1 a + (a 1) b

These two solutions correspond to x = (b 1), y = 1, and to x = 1, y = a 1. In


both cases, we do not get a solution with nonnegative x and y. Hence N = xa + by has
no solution with x and y both nonnegative.

28
10 Problem 4.3. Do the postage 140 with denominations 21 and 8.

Answer. Use 1 = sa tb from the extended Euclidean algorithm, multiple by 140, and
adjust to a nonnegative solution. This happens with = 53 in formula (pm).

1 = (3) 21 + 8 8
140 = (480) 21 + 1120 8
140 = (480 + 8) 21 + (8 21) 8
140 = (480 + 53 8) 21 + (8 53 21) 8
140 = 4 21 + 7 8

10 Problem 4.4. For any a and b relatively prime, use 1 = sa tb from the
extended Euclidean algorithm to determine x and y in (1) needed to do the postage
(a 1)(b 1).

Answer.

(a 1)(b 1) = ab a b + 1 = (b 1)a b + sa tb
(odd) = (b 1 + s)a + (t 1)b
(even) = (s 1)a + (a 1 t)b

The solution (odd) turns out to be nonnegative for an odd number m of steps in the
Euclidean algorithm. Because of |s| 2b and t < 0, we get x = b 1 + s 0 and
y = t 1 0.
The solution (even) yields x = s 1, y = a + t 1. Because of s > 0 and |t| a2 , this
alternative gets nonnegative for an even number m of steps in the Euclidean algorithm.

5 The Speed of Convergence


We now investigate how fast the Euclidean algorithm is. One needs the Fibonacci
sequence

F0 = 0, F1 = 1, F2 = 1, F3 = 2, F4 = 3, F5 = 5, F6 = 8, . . .
Fi+1 = Fi + Fi1 for all i 1

Proposition 5.1. Let q 0, m 1 be any integers. The Euclidean algorithm needs


exactly m steps for the following examples:

(1) a = Fm+2 + qFm+1 , b = Fm+1 , m1


(2) a= Fm , b = Fm+1 + qFm , m 2

10 Problem 5.1. Check these statements, extended mode, with

29
(a) m = 6, q = 2 and
(b) m = 6, q = 0.
Answer. (a) m = 6, q = 2

row 0: 1 0
row 1: 47 : 13 = 3 rem 8 0 1
row 2: 13 : 8 = 1 rem 5 1 3
row 3: 8: 5= 1 rem 3 1 4
(5.1)
row 4: 5: 3= 1 rem 2 2 7
row 5: 3: 2= 1 rem 1 3 11
row m=6: 2: 1= 2 rem 0 5 18
row m+1: 13 47

row 0: 1 0
row 1: 8 : 29 = 0 rem 8 0 1
row 2: 29 : 8 = 3 rem 5 1 0
row 3: 8: 5= 1 rem 3 3 1
(5.2)
row 4: 5: 3= 1 rem 2 4 1
row 5: 3: 2= 1 rem 1 7 2
row m=6: 2: 1= 2 rem 0 11 3
row m+1: 29 8

(b) m = 6, q = 0

row 0: 1 0
row 1: 21 : 13 = 1 rem 8 0 1
row 2: 13 : 8 = 1 rem 5 1 1
row 3: 8: 5= 1 rem 3 1 2
(5.3)
row 4: 5: 3= 1 rem 2 2 3
row 5: 3: 2= 1 rem 1 3 5
row m=6: 2: 1= 2 rem 0 5 8
row m+1: 13 21

row 0: 1 0
row 1: 8 : 13 = 0 rem 8 0 1
row 2: 13 : 8 = 1 rem 5 1 0
row 3: 8: 5= 1 rem 3 1 1
(5.4)
row 4: 5: 3= 1 rem 2 2 1
row 5: 3: 2= 1 rem 1 3 2
row m=6: 2: 1= 2 rem 0 5 3
row m+1: 13 8

30
Reason for proposition 5.1. For example (1), the Euclidean algorithm consists of these
m steps:

row 1: a: b= q + 1 rem Fm
row 2: b: Fm = 1 rem Fm1
row 3: Fm : Fm1 = 1 rem Fm2
(5.5)
row i: Fm+3i : Fm+2i = 1 rem Fm+1i
row m-1: F4 : F3 = 1 rem 1
row m: F3 : F2 = 2 rem 0

For example (2), only the two first steps are different. Here are all m steps:

row 1: a: b= 0 rem Fm
row 2: b: Fm = q + 1 rem Fm1
row 3: Fm : Fm1 = 1 rem Fm2
(5.6)
row i: Fm+3i : Fm+2i = 1 rem Fm+1i
row m-1: F4 : F3 = 1 rem 1
row m: F3 : F2 = 2 rem 0

Proposition 5.2. Let a and b be positive integers. If the Euclidean algorithm needs m
steps, then

(5.7) b gcd(a, b) Fm+1


(5.8) a gcd(a, b) Fm+2 if a > b

Proof. The claim is obvious for m = 1.In this case, b divides a and b = gcd(a, b).
Suppose the Euclidean algorithm needs m 2 steps. Hence the last quotient qm 2.
Following the remainders backwards yields

rm = gcd(a, b) = gcd(a, b) F2
rm1 2rm = gcd(a, b) F3
rm2 rm + rm1 gcd(a, b) F4

and inductively for i = m 1, m 2 . . . 2

(rup) ri1 ri+1 + qi ri ri+1 + ri gcd(a, b) Fm+3i

For i = 2, we get the first claim b gcd(a, b) Fm+1 . If a > b, we know that q1 1, and
hence i = 1 can be included in the estimate (rup). Thus one confirms the second claim
a gcd(a, b) Fm+2 .

31
Proposition 5.3. Let a and b be positive integers. If

(Fn) either b Fn+1 with n 1 or a Fn with n 2

the number m of steps in the Euclidean algorithm satisfies m n. Under assump-


tion (Fn), the algorithm takes m = n steps exactly for the examples (1) and (2) given
in proposition 5.1 above.

Proof. If b F2 = 1 and n = 1, then m = 1 is obvious. Now suppose that b Fn+1


and m n 2. From estimate (5.7), we conclude

(5.9) Fm+1 gcd(a, b) Fm+1 b Fn+1 Fm+1

Hence m = n, b = Fm+1 , and gcd(a, b) = 1. Equality holds for the entire sequence
of estimates (rup) and hence qi = 1 for i = 2 . . . m 1 and qm = 2. One gets r2 =
gcd(a, b) Fm = Fm , hence a = q1 b + r2 = q1 Fm+1 + Fm = (q1 1)Fm+1 + Fm+2 . In
case that q1 1, we get example (1). Or, as an exceptional case q1 = 0, we conclude
a = r2 = Fm and b = Fm+1 , which is example (2) with q = 0.
If a F2 = 1 and n = 2, then m 2 is obvious. Secondly, suppose that a Fn
and m n 3. Distinguish the cases (a):a b and (b):a < b. Case (a) cannot occur,
because gcd(a, b)Fm+2 a Fn Fm leads to a contradiction.
In case (b), the first quotient is zero and first three remainders are r0 = a, r1 = b, r2 =
a. After discarting the first step, we get a Euclidean algorithm with m 1 n 1 2
steps, for which the first entry is now b and second entry is a Fn . As explained above,
one concludes

(5.10) Fm gcd(b, a) Fm a Fn Fm

Hence m = n and a = Fm , gcd(a, b) = 1, r3 = Fm1 . Because of b = r1 = q2 r2 + r3 =


(q + 1)r2 + r3 = (q + 1)Fm + Fm1 = qFm + Fm+1 , we get example (2).
The golden number and the explicit formula for the Fibonacci numbers are

5+1 n (1)n n
(5.11) := , Fn =
2 5
This formula can be inverted. For all n 2, one gets
 
log Fn log 2
(Fibinverse) n= +3
log

10 Problem 5.2. Calculate the Fibonacci numbers and check the inversion for-
mula (Fibinverse) for n 12.

32
Theorem 5.1 (Logarithmic effectiveness of the Euclidean Algorithm). The
number of steps m(a, b) the Euclidean algorithm takes is bounded above by
(5.12)    
log a log 2 log gcd(a, b) log b log 2 log gcd(a, b)
m(a, b) min +3 , +2
log log
Proof. Independent verification We may assume a 6= b since the case a = b is obvious.
Because of qi 1 for 2 i m and even qm 2, equation (1.6) implies inductively
si Fi1 for i = 1, 2 . . . m. Corollary 1.3 implies now
b
(5.13) = sm+1 2sm + sm1 2Fm1 + Fm2 = Fm+1
gcd(a, b)
with m = m(a, b). Hence the inversion formula (Fibinverse) implies
   
log Fm+1 log 2 log b log 2 log gcd(a, b)
(5.14) m(a, b) + 1 = +3 +3
log log
To get an estimate of m(a, b) in terms of a, we distinguish the cases
(a): a < b
(b): a > b
(c): a = b
In case (a), the algorithm starts with the remainders a, b, a. Discarting the first step
yields
 
log a log 2 log gcd(a, b)
(5.15) m(a, b) 1 = m(b, a) +2
log
as claimed. In case (b), we consider the prolonged algorithm starting with the remainders
a + b, a, b from which one gets
 
log a log 2 log gcd(a, b)
(5.16) m(a, b) = m(a + b, a) 1 +1
log
which yields an estimate of m(a, b) betterby twothan the one claimed.

6 Reversing the Extended Euclidean Algorithm


Proposition 6.1. In the extended Euclidean algorithm, the sequences si 0 for i =
1, 2 . . . m + 1, and ti 0 for i = 2, 3 . . . m + 1 are nondecreasing. The reversed sequences
sm+1 , sm , sm1 , . . . and tm+1 , tm , tm1 , . . . are successive remainders in two other in-
stances of the Euclidean algorithm except possibly for the number 1 occurring twice at
the very end, as explained in problem 6.3 below.

33
Proof. The proof is done by induction: The start at i = 1, 2 is s1 = 0, s2 = 1, and
t1 = 0, t2 = q1 0, is obvious, as is the induction step.
10 Problem 6.1. Use the extended algorithm for gcd(4321, 1234) from prob-
lem 4, to get another instance of the Euclidean algorithm from the reversed sequence
sm+1 , sm , sm1 , . . . . Use extended mode, and check what happens at the very last steps.
Answer. The reversed sequences sm+1 , sm , sm1 , . . . occurs in the Euclidean algorithm
row 0: 1 0
row 1: 1234 : 309 = 3 rem 307 0 1
row 2: 309 : 307 = 1 rem 2 1 3
(6.1)
row 3: 307 : 2 = 153 rem 1 1 4
row m=4: 2: 1= 2 rem 0 154 615
row m+1: 309 1234

10 Problem 6.2. Use the extended algorithm for gcd(4321, 1234) from prob-
lem 1.2, to get another instance of the Euclidean algorithm from the reversed sequence
tm+1 , tm , tm1 , . . . . Use extended mode, and check what happens at the very last steps.
Answer. The reversed sequences tm+1 , tm , tm1 , . . . occurs in the Euclidean algorithm
row 0: 1 0
row 1: 4321 : 1082 = 3 rem 1075 0 1
row 2: 1082 : 1075 = 1 rem 7 1 3
row 3: 1075 : 7= 153 rem 4 1 4
(6.2)
row 4: 7: 4= 1 rem 3 154 615
row 5: 4: 3= 1 rem 1 155 619
row m=6: 3: 1= 3 rem 0 309 1234
row m+1: 1082 4321

10 Problem 6.3. There are only three cases in which two consecutive equal terms
in the sequences si 0 for i = 1, 2 . . . m + 1, or ti 0 for i = 2, 3 . . . m + 1. Find these
cases and give examples containing them.
Answer. 1. s2 = s3 = 1 occurs in case that q2 = 1.
2. t1 = t2 = 1 occurs in case that q1 = 1.
3. t3 = t4 = 1 occurs in case that q1 = 0, q3 = 1.
Proposition 6.2 (Reversing the Euclidean Algorithm). Assume a > 2b. The
reversed second extension column tm+1 , tm , tm1 , . . . gives another instance of the Eu-
clidean algorithm which has remainders and quotients
rei = tm+1i for i = 0, 1, 2 . . . m + 1
(6.3)
qei = qm+1i for i = 1, 2 . . . m

34
The extension column of the newly constructed algorithm
rm+1i
(6.4) tei =
gcd(a, b)
is proportional to the original remainders reversed.
Problems 1.2 and 6.2 give an example for two mutually reversed algorithms.

7 Descartes Problem
Given is an integer A 2. In how many ways can one write A as a sum of two squares

(desc) A = a2 + b2 with integers a b 0

Take for example A = 125. There are two solutions: 125 = 102 + 52 = 112 + 22 . For
A = 25, we get the two solutions 25 = 52 + 02 = 42 + 32 .
Definition 7.1 (Descartes restricted sum of squares problem). Given is an
integer A 3. How many solutions are there for

(restr-sq) A = a2 + b2 with integers a > b 1 and gcd(a, b) = 1

For A = 125, there is just one solution 125 = 112 + 22 . In this essay, I want to
concentrate on the restricted problem. The Euclidean algorithm helps to establish the
following result:
Theorem 7.1 (Counting the solutions of the restricted problem). We fix a value
A 3 for the sum. There exists a bijection between the solutions of the restricted sum
of squares problem and the solutions of the congruence
A
(imag) 1 + J2 0 mod A and 1J <
2
Hence both problems have the same number of solutions.
This theorem is useful for the practical calculation of the solution of Descartes
problem for a given very large number A, too. Indeed, a solution J of system (imag)
can be found much quicker than a direct solution of Descartes problem is possible.
Reason. Let p 1 mod 4 be a prime number, and r a primitive root. Eulers theorem
implies
p1
r 2 1 mod p
p1
and hence one of J := r 4 mod p yields a solution of (imag). Thus the congru-
ence (imag) can be solved much faster than Descartes problem, which can afterwards
be solved by the method elaborated below.

35
By proposition 7.8 and proposition 7.9 below, one needs just half of a simple Eu-
clidean algorithm starting with A and J, to effectively calculate a solution of Descartes
restricted problem. Furthermore, by theorem 7.1 above, starting from a complete list
of solutions of congruence (imag) leads to a complete list of solutions of Descartes
restricted problem.
To construct the bijection J (a, b), we begin with a remark linking the extended
Euclidean algorithm to complex arithmetic. Besides calculating the greatest common
divisor, the extended Euclidean algorithm expresses it as an integer combination
(*m) (1)m gcd(a, b) = sm a tm b
Using complex Gaussian integers and the imaginary unit j 2 = 1 one rewrites this
equation and its absolute square as
(sm + tm j) (a + bj) = (1)m gcd(a, b) + Jj
(***)
(s2 + t2 ) (a2 + b2 ) = gcd(a, b)2 + J 2
Again m(a, b) is the number of steps of the Euclidean algorithm, and J 1 is defined
as
(7.1) J := sm b + tm a
Proposition 7.1 (Mapping (a, b) 7 J). Assume that a > b and gcd(a, b) = 1. The
congruence
a2 + b 2
(imag) 1 + J2 0 mod a2 + b2 and 1J <
2
has the solution J = sm b + tm a. Furthermore, in the ring of Gaussian integers, either
1 + Jj or 1 Jj is a multiple of a + bj, depending on whether the number m(a, b) of
steps of the algorithm is even or odd.
Proof. Because of the squared formula in (***), the value J from formula (7.1) is a
solution of (imag). Furthermore since a 6= b is assumed,
b a
(**) |sm | and |tm |
2 gcd(a, b) 2 gcd(a, b)
as has been shown in corollary 1.4. This estimate implies
a2 + b 2
1J
2 gcd(a, b)
We can exclude the maximal value since
(a2 + b2 )2
gcd(a, b)2 + J 2 = (s2 + t2 ) (a2 + b2 )
4 gcd(a, b)2
1

1 a2 +b2
Actually the maximal value J = 2 gcd(a,b) occurs if and only if a = b.

36
To construct the inverse mapping J 7 (a, b), we need to carefully investigate the
Euclidean algorithm starting with a2 + b2 and J.
Definition 7.2. I call a Euclidean algorithm self-symmetric if and only if

(self-symm) qi = qm+1i for i = 1, 2 . . . m

10 Problem 7.1. Is the Euclidean algorithm for a = 91 and b = 27 self-


symmetric?
Answer.
91 : 27 = 3 rem 10
27 : 10 = 2 rem 7
(7.2) 10 : 7 = 1 rem 3
7 : 3 = 2 rem 1
3 : 1 = 3 rem 0

The algorithm is self-symmetric and needs m = 5 steps.


Proposition 7.2 (Properties of the self-symmetric algorithm).
rm+1i
(str) ti = for i = 0, 1 . . . m + 1
gcd(a, b)
(gcdt) gcd(ti , ti+1 ) = 1 for i = 0, 1 . . . m
a
(prod) ti+1 tm+1i + ti tmi = for i = 0, 1 . . . m
gcd(a, b)
b a
(sm+1) tm = sm+1 = , tm+1 =
gcd(a, b) gcd(a, b)
a b2
(sm) sm = (1)m +
gcd(a, b) gcd(a, b)2
Reason. The symmetry assumption (self-symm) implies that

ti+1 = ti1 + qi ti
rmi = rm+2i + qm+1i rm+1i = rm+2i + qi rm+1i

for all i = 1, . . . m. Furthermore,


rm+1
t0 = =0
gcd(a, b)
rm
t1 = =1
gcd(a, b)
Hence equation (str) follows inductively for all i = 0, 1 . . . m + 1. Since gcd(ri , ri+1 ) =
gcd(a, b) for any two successive remainders, formula (str) implies that successive ti and

37
ti+1 are relatively prime for i = 0, 1 . . . m. Corollary 1.3 and formula (str) for i = m
imply
b r1
sm+1 = = = tm
gcd(a, b) gcd(a, b)
and the other formula of (sm+1), too. The determinant identity

(det-r) ri ti+1 + ri+1 ti = a for i = 0, 1 . . . m

and (str) imply


ri ti+1 + ri+1 ti a
(prod) tm+1i ti+1 + tmi ti = = for i = 0, 1, 2 . . . m
gcd(a, b) gcd(a, b)

The determinant identity sm tm+1 sm+1 tm = (1)m , again from proposition 1.1, and
formula (sm+1) imply (sm).

Proposition 7.3 (Properties of the even self-symmetric algorithm). Assume that the
number of steps m = 2h of a self-symmetric algorithm is even. Then
rh+1 rh
th = and th+1 =
gcd(a, b) gcd(a, b)
a
(qh) t2h+1 + t2h =
gcd(a, b)
2 2
(qm) gcd(a, b) + b 0 mod a gcd(a, b)
m
Proof. We use formula (prod) with i = h = 2
= m i to get formula (qh). Since m is
even, formula (sm) implies

gcd(a, b)2 + b2 = sm a gcd(a, b)

which yields (qm).


Quantities referring to the even self-symmetric algorithm are now capitalized.

Proposition 7.4. We take the first two remainders to be A and some J < A such
that gcd(A, J) = 1. Assume the resulting Euclidean algorithm is self-symmetric and the
number of steps M (A, J) is even. In this case
A
(imag) 1 + J2 0 mod A and 1J <
2
Proposition 7.4 follows from (qm). More astonishingly, the converse holds, too:

Proposition 7.5. A Euclidean algorithm with initial remainder r0 = A, r1 = J which


satisfy the congruence (imag) is self-symmetric and the number of steps M (A, J) is
even.

38
Proof. The congruence (imag) implies 1 + J 2 = pA and hence gcd(A, J) = 1.
We now check how the two extension columns Si and Ti of the Euclidean algorithm
starting with R0 = A, R1 = J end. Corollary 1.3 yields

(M+1) SM +1 = J , TM +1 = A

Since gcd(A, J) = 1, formulas (*) and (**) and Corollary 1.4 imply

SM A TM J = (1)M
(7.3) J A
0 < SM and and 0 < TM
2 2
Furthermore, these properties determine SM and TM uniquely.
The assumption J < A2 implies pA = 1 + J 2 < 1 + J2 A and hence 1 p < J2 . Since
pA J 2 = 1, we get as solution of system (7.3):

SM = (1)M p , TM = (1)M J

Because SM 0 and TM 0, we see that M is even. The reversed sequence

R
fi = TM +1i for i = 0, 1, 2 . . . M + 1

starts with

R
f0 = TM +1 = A = R0
R
f1 = TM = J = R1

These happen to be just the first two remainders! Because the two initial remainders
determine the Euclidean algorithm uniquely, we conclude that

R
fi = TM +1i = Ri for i = 0, 1, 2 . . . M + 1
(sym)
Q
fi = QM +1i = Qi for i = 1, 2 . . . M

confirming that the algorithm is self-symmetric and has an even number of steps.
Proposition 7.6. Assume A > J, and gcd(A, J) = 1. The Euclidean algorithm is
self-symmetric and the number of steps M (A, J) is even, if and only if
A
(imag) 1 + J2 0 mod A and 1J <
2
Proposition 7.7. Assume a > 2b 1, and gcd(a, b) = 1. If the Euclidean algorithm is
self-symmetric and the number of steps M (a, b) is odd, then 1 + b2 is not divisible by a.
2

2
The exceptions for a = 2, b = 1 has already been excluded.

39
We can now construct the inverse mapping J 7 (a, b) going from a solution of
congruence (imag) to a solution of Descartes restricted problem.
Proposition 7.8 (Mapping (J 7 (a, b)). Assume congruence (imag) holds. Then
A and J are the first two remainders of an even self-symmetric Euclidean algorithm.
Furthermore, the two remainders Rh and Rh+1 with h = M2 just halfway through the
algorithmyield a solution of Descartes restricted problem
2
A = Rh+1 + Rh2 , Rh+1 > Rh 1 and gcd(Rh+1 , Rh ) = 1

Proposition 7.8 follows from (qh). This proposition is useful for the practical cal-
culation of a solution of Descartes problem for a given very large number A, because
indeed, a solution J of system (imag) can be found much quicker than a solution of
Descartes problem.
In this setting, one needs only to calculate half of simple Euclidean algorithm start-
ing with A and J, since it is easy determine when step h + 1 has been reached:
Proposition 7.9. For the Euclidean algorithm of proposition 7.8, the remainder Rh is
the first remainder the square of which is less than A.
Proof.

Rh1 = qh Rh + Rh+1 Rh + Rh+1


2
Rh1 (Rh + Rh+1 )2 > Rh2 + Rh+1
2
=A
2
Rh1 > A > Rh2

We need still to check that the mapping : (a, b) 7 J given by proposition 7.1 has
the mapping : J 7 (a, b) from proposition 7.8 as its inverse.

a > eb 1 of Descartes restricted problem


Proposition 7.10. Each solution e

(restr-sq) a2 + eb2 with integers e


A=e a > eb 1 and gcd(e
a, eb) = 1

corresponds to an even self symmetric doubled Euclidean algorithm.


Reason. We use the extended Euclidean algorithms starting with the two remainders
a, eb. Let the number of its steps be m = m(e
e a, eb). The sequence

Tm+i := sieb + tie


a for i = 0, 1, 2 . . . m + 1

starts with Tm = eb and Tm+1 = e


a in this reversed order. It is increasing, and it satisfies
the recursion

(sT+) Tm+i+1 = Tm+i1 + qi Tm+i

40
parallel to the second of equations (1.6). From the reversed sequence

R0 = T2m+1 , R1 = T2m , . . . , Ri = T2m+1i , . . . , Rm = Tm+1 = e


a, Rm+1 = Tm = eb

we get the first half of the sequence of remainders for the doubled Euclidean algorithm,
which turns out to be even and self-symmetric.
Furthermore, this doubled algorithm contains Rm = e a, Rm+1 = eb as two successive
M
remainders occurring in the middle at step m = 2 . It is clear that the remainders
following afterwards for i > M2 agree with those already calculated, hence

Rm+i = ri = (1)i [sie


a tieb] for i = 0, 1, 2 . . . m + 1

We now combine the formulas for the remainders after and before the middle index m.
Using complex Gaussian integers with imaginary unit j 2 = 1, one gets

Rm+i ; = Tmi+1 := (1)i [siea tieb]


(7.4) Rmi+1 := Tm+i := sieb + tie a
i
(1) Rm+i + Rmi+1 j = (si + ti j) (e
a + ebj)

for i = 0, 1, 2 . . . m + 1.
With i = m and J := R1 = smeb + tme
a, one confirms

a + ebj) = (1)m + R1 j
(sm + tm j) (e
(***)
(s2 + t2 ) (e
a2 + eb2 ) = 1 + R12

Hence we get a solution of congruence imag, too.


Especially for i = m + 1, we can take advantage of corollary 1.3 once more and get:

aj) (e
(eb + e a + ebj)
(1)m+1 R2m+1 + R0 j = (sm+1 + tm+1 j) (e
a + ebj) = a2 + eb2
=e
gcd(ea, b)
e

The doubled Euclidean algorithmstarting with remainders T2m+1 and T2m has the
sequence of remainders containing

R0 = T2m+1 = a2 + eb2
e
R1 = T2m = smeb + tme a, . . .
Rm = Tm+1 = a,
(7.5)
e
Rm+1 = Tm = eb, . . .
m
R2m = T1 = (1) [sme a tmeb] = 1,
R2m+1 = T0 = 0

The algorithm is self-symmetric with quotients Qmi+1 = Qm+i = qi for i = 1, 2 . . . m


and takes M (A, B) = 2m steps.

41
Example 7.1. At first, one calculates the second half of the algorithm, starting with
the division 10 : 7. The three extension columns contain si ti and Tm+i = si b + ti a.
This third extension contains b, a is the middle. It can be completed forwards using the
iteration (sT), parallel to (st). It is easily completed backwards, because by construction,
the doubled algorithm is self symmetric.
(a) a = 10, b = 7

row : 149 : 44 = 3 rem 17 (1)


row : 44 : 17 = 2 rem 10 (2)
row : 17 : 10 = 1 rem 7 7
(7.6)
row i=1: 10 : 7= 1 rem 3 0 1 10
row 2: 7: 3= 2 rem 1 1 1 17
row m=3: 3: 1= 3 rem 0 2 3 44
row m+1: 7 10 149

As results, we get the integer combination

(1)3 gcd(10, 7) = 1 = 2 10 3 7

and the Gaussian product

(2 + 3j) (10 + 7j) = 1 + 44j


(***)
(22 + 32 ) (102 + 72 ) = 1 + 442 0 mod 149

(b) a = 5, b = 4

row : 41 : 9 = 4 rem 5 (1)


row : 9 : 5 = 1 rem 4 4
(7.7)
row i=1: 5: 4 = 1 rem 1 0 1 5
row m=2: 4: 1 = 4 rem 0 1 1 9
row m+1: 4 5 41

As results, we get the integer combination

gcd(5, 4) = 1 = 1 5 1 4

and the Gaussian product

(1 + j) (5 + 4j) = 1 + 9j
(***)
(1 + 12 ) (52 + 42 ) = 1 + 92 0
2
mod 41

42
Proposition 7.11. The mapping : (a, b) 7 J from proposition 7.1:
A := a2 + b2 and J := sm b + tm a
has the mapping : J 7 (a, b) from proposition 7.8 as its inverse. In the Euclidean
algorithm starting with A and J, the two numbers (a, b) are the two remainders appearing
in the middle of the algorithm as a = Rh and b = Rh+1 at step h = M2 .
Theorem 7.2 (Correspondence of solutions for Descartes restricted problem
and the congruence for the imaginary unit). Assume A 3. There is a bijective
correspondence between
a > eb 1 of Descartes restricted problem
(a) solutions e

(restr-sq) a2 + eb2 with integers e


A=e a > eb 1 and gcd(e
a, eb) = 1

(b) even self symmetric Euclidean algorithm with the two middle remainders Rm = e
a
M
and Rm+1 = b for m = 2 .
e

(c) solutions of the congruence


A
(imag) 1 + J2 0 mod A and 1J <
2
(d) even self symmetric Euclidean algorithm starting with first two remainders A, J.
Hence the number of solutions of the restricted sum of squares problem (rest-sq) is equal
to the number of solutions of the congruence (imag).
Example 7.2. The next four examples all take A = 1105. I cover all four solutions
J = 47 , 242 , 268 , 463 of
1105
1 + J2 0 mod 1105 , 1J <
2
and get the four corresponding decompositions of
1105 = a2 + b2
into a sum of two squares. The Euclidean algorithm allows one to go back and fourth
between the two problems. The three extension columns are si , ti and Tm+i .

(c1) a = 24, b = 23
row : 1105 : 47 = 23 rem 1 (1)
row : 47 : 24 = 1 rem 23 23
(7.8)
row i=1: 24 : 23 = 1 rem 1 0 1 24
row m=2: 23 : 1 = 23 rem 0 1 1 47
row m+1: 23 24 1105

43
The doubled self-symmetric algorithm starts with the division 1105 : 47. The second
half of the algorithm starts with the division 24 : 23. We get the integer combination
gcd(24, 23) = 1 = 1 24 1 23
and the Gaussian product
(1 + j) (24 + 23j) = 1 + 47j
(***)
(1 + 12 ) (242 + 232 ) = 1 + 472 0
2
mod 1105

(c2) a = 32, b = 9
row : 1105 : 242 = 4 rem 137 (1)
row : 242 : 137 = 1 rem 105 (4)
row : 137 : 105 = 1 rem 32 (5)
row : 105 : 32 = 3 rem 9 9
(7.9)
row i=1: 32 : 9= 3 rem 5 0 1 32
row i=2: 9: 5= 1 rem 4 1 3 105
row i=3: 5: 4= 1 rem 1 1 4 137
row m=4: 4: 1= 4 rem 0 2 7 242
row m+1: 9 32 1105
The doubled self-symmetric algorithm starts with the division 1105 : 242. The second
half of the algorithm starts with the division 32 : 9. We get the integer combination
gcd(32, 9) = 1 = 2 32 7 9
and the Gaussian product
(2 + 7j) (32 + 9j) = 1 + 242j
(***)
(22 + 72 ) (322 + 92 ) = 1 + 2422 0 mod 1105

(c3) a = 33, b = 4
row : 1105 : 268 = 4 rem 33 (1)
row : 268 : 33 = 8 rem 4 4
(7.10)
row i=1: 33 : 4= 8 rem 1 0 1 33
row m=2: 4: 1= 4 rem 0 1 8 268
row m+1: 4 33 1105
The doubled self-symmetric algorithm starts with the division 1105 : 47. The second
half of the algorithm starts with the division 24 : 23. We get the integer combination
gcd(33, 4) = 1 = 1 33 8 4

44
and the Gaussian product

(1 + 8j) (33 + 4j) = 1 + 268j


(***)
(12 + 82 ) (332 + 42 ) = 1 + 2682 0 mod 1105

(c4) a = 31, b = 12

row : 1105 : 463 = 2 rem 179 (1)


row : 463 : 179 = 2 rem 105 (2)
row : 179 : 105 = 1 rem 74 (5)
row : 105 : 74 = 1 rem 31 (7)
row : 74 : 31 = 2 rem 12 12
(7.11)
row i=1: 31 : 12 = 2 rem 7 0 1 31
row i=2: 12 : 7= 1 rem 5 1 2 74
row i=3: 7: 5= 1 rem 2 1 3 105
row i=4: 5: 2= 2 rem 1 2 5 179
row m=5: 2: 1= 2 rem 0 5 13 463
row m+1: 12 31 1105

The doubled self-symmetric algorithm starts with the division 1105 : 242. The second
half of the algorithm starts with the division 32 : 9. We get the integer combination

(1)5 gcd(31, 12) = 1 = 5 31 13 12

and the Gaussian product

(5 + 13j) (31 + 12j) = 1 + 463j


(***)
(52 + 132 ) (312 + 122 ) = 1 + 4632 0 mod 1105

Theorem 7.3 (Solution for square free integers). Assume that A 3 has only simple
prime factors, also called square free. Under that additional assumption, the number of
solutions of Descartes problem is equal to the number of solutions of the congruence
A
(imag) 1 + J2 0 mod A and 1J <
2

45

Vous aimerez peut-être aussi