NumberTheory Chapter 02 GCD Eng
NumberTheory Chapter 02 GCD Eng
Definition 2:
The Greatest Common Divisor (GCD), of the integers a and b, is that divisor of a and b
which is the largest of them all.
Notation 1:
We indicate the Greatest Common Divisor of a and b as gcd(a, b).
Remark 1:
Sometimes (a, b) is used to indicate the GCD, however this does lead to confusion in cases and
we shall stick to the proper version, but note that in other reading material the (a, b) version
might occur.
Remark 2:
Note that the GCD is always a positive number. If c is negative and a common divisior of a
and b then −c is also a common divisor of a and b, but then we have that −c is positive and
hence greater than c. Therefore there must always be a positive common divisor and thus the
GCD of two numbers is always positive.
Theorem 1:
If a and b are integers, at least one of them non-zero, then gcd(a, b) exists.
Proof:
QED
Example 1:
We demonstrate some greatest common divisors with actual numbers.
• gcd(3, 7) = 1
• gcd(21, 14) = 7
• gcd(30, 24) = 6
• gcd(0, 0) does not exists, since one of the numbers isn’t non-zero.
Proof:
QED
Remark 3:
This theorem is very important and we shall refer to it again when trying to find solutions to
equations. For example, if we are asked to find solutions to the equation 5x + 7y = 1 then at
least Bezout’s Theorem tells us that there will be solutions since gcd(5, 7) = 1. Thus, now we
know that we can try to find the solutions. On the other hand, if we are asked to find solutions
to 21x + 28y = 1, Bezout’s Theorem tells us that there are no solutions since gcd(21, 28) = 7.
Thus the first step is to use this theorem to check whether there are solutions or whether there
aren’t solutions.
Theorem 3:
If the integers a and b have a gcd(a, b) then every common divisor of a and b divides gcd(a, b).
Proof:
QED
Properties
Property 1: gcd(a, b) = gcd(b, a).
Property 5: For any integer c, gcd(a, b) = gcd(a, b + ac) = gcd(a + bc, b).
Property 8: gcd((a, b), c) = gcd(a, (b, c)) for any integers a, b and c.
Remark 4:
We quickly show why each of the above properties are indeed true.
1) Surely the greatest common divisor of a and b is also the greatest common divisor of b
and a.
2) a|a and a|b, hence (|a|)|a and (|a|)|b, and therefore |a| is a common divisor of a and b.
Suppose that there is a larger common divisor. Let d be this larger common divisor. So
d|a, and hence d|(|a|), but by definition d > |a| which is a contradiction since d|(|a|).
Thus |a| is indeed the largest common divisor of a and b.
4) Let d = gcd(a, b). Hence d|a and d|b. Therefore d|−a and d|−b. Hence d is a common
divisor of any combination of these. Suppose that either a and −b or −a and b or −a and
−b has a common divisor e, which is larger than d. But then e|a and e|b so e|d, which is
a contradiction. So d is in fact the greatest common divisor of all of them.
5) Let d = gcd(a, b) and e = gcd(a, b + ac). Then d|b + ac, hence d|e. On the other hand
there are some integers u and v such that d = au + bv = a(u − vc) + (b + ac)v. Thus e|d
and therefore d = e. So gcd(a, b) = gcd(a, b + ac). Similarly, gcd(a, b) = gcd(a + bc, b).
6) Let d = gcd(ma, mb) and e = gcd(a, b). Since e|a, (me)|(ma). Since e|b, (me)|(mb).
Therefore (|m|e)|(ma) and (|m|e)|(mb). Thus (|m|e)|d. Furthermore, |m|e = m(au + bv)
for some integers u and v. So |m|e = m(au + bv) = (ma)u + (mb)v. Thus d|(|m|e).
Therefore gcd(ma, mb) = |m|gcd(a, b).
7) Assume d > 0 since otherwise we can just change d to −d. Let e = gcd( ad , db ) and
f = gcd(a, b). Then a = da0 , b = db0 and by Property 6, f = dgcd(a0 , b0 ) = de, hence
e = fd .
8) Let d = gcd((a, b), c) and e = gcd(a, (b, c)). Let f = gcd(a, b) and g = gcd(b, c). Now d|f
and d|c. Since d|f , d|a and d|b. Hence d|a, d|b and d|c. So d|a and d|g. Therefore d|e.
Similarly e|d. Thus gcd((a, b), c) = gcd(a, (b, c)).
Remark 5:
Just as a reminder |x| means the absolute value of x and the absolute value of an integer is just
the integer without the sign. Thus if x is negative |x| just drops the sign. For instance, |5| = 5
and | − 5| = 5. So anything between the | . . . | is just made positive.
Remark 6:
We can also generalize the definition of greatest common divisor to more than two variables.
We can therefore also generalize Theorem 1, 2 and 3.
Definition 3:
The Greatest Common Divisor (GCD), of the integers a1 , a2 , . . . ak , is that divisor of
a1 , a2 , . . . ak−1 and ak which is the largest of them all.
Notation 2:
We indicate the Greatest Common Divisor of a1 , a2 , . . . ak as gcd(a1 , a2 , . . . ak ).
3) If R = 0 then gcd(a, b) = Y and the algorithm ends. If not, continue with 4).
Proof:
We will leave this as an exercise.
Example 2:
Compute the greatest common divisor of 162 and 24.
Step 1) So X = 162 and Y = 24
Step 2) 162 = 6 × 24 + 18
Step 3) The remainder R = 18 and not 0. Thus we contnue with step 4.
Step 4) X = 24 and Y = 18. Step 2) Second time. 24 = 1 × 18 + 6
Step 3) Second time. The remainder R = 6 and not 0. Thus continue with step 4.
Step 4) Second time. X = 18 and Y = 6.
Step 2) Third time. 18 = 3 × 6 + 0.
Step 3) Third time. R = 0 and we stop. So gcd(162, 24) = 6.
Example 3:
We could also have condensed it a bit. Compute the greatest common divisor of 1001 and 209.
1001 = 4 × 209 + 165
209 = 1 × 165 + 44
165 = 3 × 44 + 33
44 = 1 × 33 + 11
33 = 3 × 11 + 0
Thus gcd(1001, 209) = 11.