Poly Euclid Algorithm
Poly Euclid Algorithm
Poly Euclid Algorithm
Tutorial 2:
The Euclidean algorithm
1
2 Greatest common divisor and least com-
mon multiple
Let a and b be two positive integers. If d is a divisor of a and also a divisor of
b, then we say that d is a common divisor of a and b. As there are only a finite
number of common divisors, there is a greatest common divisor, denoted by
gcd (a, b). The number m is said to be a common multiple of a and b if m is a
multiple of a and also a multiple of b. Among all common multiples there is a
minimal one (Least-integer principle!). It is called the least common multiple
and it is denoted by lcm (a, b).
In the decomposition (1) we had all exponents positive. However, some-
times it is convenient to allow some exponents to be 0. This is especially
convenient, when we consider prime factorisations of two numbers a and b,
looking for gcd (a, b) and lcm (a, b), since we may assume that both a and b
have the same set of primes in their prime factorisations.
Theorem 2. Let
and
max(α1 ,β1 ) max(α2 ,β2 )
lcm (a, b) = p1 p2 . . . pmax(α
r
r ,βr )
. (5)
Moreover,
Proof. Formulas (4) and (5) follow from our description of common divisors
and common multiples. To prove (6) we have to notice that min(αi , βi ) +
max(αi , βi ) = αi + βi .
We suspect (in fact it is an open question) that prime factorisation is
computationally difficult and we don’t know easy algorithms for that but
fortunately the greatest common divisor gcd (a, b) of numbers a and b can be
found without knowing the prime factorisations for a and b. This algorithm
was known to Euclid and maybe even was discovered by him.
2
Theorem 3 (The Euclidean Algorithm). Let a and b be positive inte-
gers. We use the division algorithm several times to find:
a = q1 b + r1 , 0 < r1 < b,
b = q2 r1 + r2 , 0 < r2 < r1 ,
r1 = q3 r2 + r3 , 0 < r3 < r2 ,
..
.
rs−2 = qs rs−1 + rs , 0 < rs < rs−1,
rs−1 = qs+1 rs .
3
Rk := Rk−2 − qk−2 Rk−1 . Eventually we will obtain the table:
a 1 0
b 0 1
r1 1 −q1
r2 −q 1 + q q .
2 1 2
..
.
rs m n
Proof. We will prove this by induction. Let the kth row of the table be
Rk = (uk , vk , wk ).
We assume that ui = avi +bwi for all i < k. This is certainly true for i = 1, 2.
Then by induction hypothesis
Thus the statement ui = avi + bwi is true for all i. In particular, this is true
for the last row, which gives us rs = am + bn.
4
321 · 843
and therefore gcd (321, 843) = 3 and lcm (321, 843) = = 107 · 843 =
3
90201. The Extended Euclidean algorithm:
321 1 0
843 0 1
321 1 0
201 −2 1
120 3 −1
81 −5 2
39 8 −3
3 −21 8
obtaining the linear presentation gcd (321, 843) = 3 = (−21) · 321 + 8 · 843.
5
Proof. Let us prove first, that there exists at most one integer N with the
conditions required. Assume, on the contrary, that for two integers N1 and
N2 we have 0 ≤ N1 < ab, 0 ≤ N2 < ab and
r − s = (r − s)ma + (r − s)nb = m0 a + n0 b.
N = r − m0 a = s + n0 b
satisfies the condition (7). If N does not satisfy 0 ≤ N < ab, we divide N by
ab with remainder N = q · ab + N1 . Now 0 ≤ N1 < ab and N1 satisfies (7).
Theorem is proved.
This is a constructive proof of the Chinese remainder theorem, which
gives also an algorithm of calculating such N with property (7). A shorter
but nonconsructive proof, which uses Pigeonhole principle can be found in the
training material ”Pigeonhole Principle.” It is used there to prove Fermat’s
theorem that any prime of the type 4n + 1 can be represented as a sum of
two squares.