Arkansas Tech University MATH 4033: Elementary Modern Algebra Dr. Marcel B. Finan 12 Greatest Common Divisors. The Euclidean Algorithm As mentioned at the end of the previous section, we would like to establish a condition on n so that (Z∗n , ) is a group. This section provides the tool needed for that. We start this section with the following definition. Definition 12.1 Let a and b be two integers, not both zero. A positive integer d is called a greatest common divisor of a and b if the following two conditions hold: (1) d|a and d|b. (2) If c|a and c|b then c|d. We write d = (a, b) or d = gcd(a, b). Example 12.1 The greatest common divisor of -42 and 56 is 14. The greatest common = − 34 divisor is useful for writing fractions in lowest term. For example, − 42 56 where we cancelled 14 = (42, 56). We next discuss a systematic procedure for finding the greatest commom divisor of two integers, known as the Euclid’s Algorithm. For that purpose, we need the following result. Theorem 12.1 If a, b, q, and r are integers such that a = bq + r then (a, b) = (b, r). Proof. Let d1 = (a, b) and d2 = (b, r). We will show that d1 = d2 . Since d2 |bq and d2 |r then by Theorem 10.2(a)(b), d2 |(bq + r). That is d2 |a. Thus, by Definition 12.1, d2 |d1 . Since d1 |b then by Theorem 10.2(a) d1 |bq. Since d1 |a then by Theorem 10.2(b)d1 |(a − bq). That is, d1 |r. Hence, from the definition of 1 d2 , we have d1 |d2 . Since d1 and d2 are positive then by Theorem 10.2(d), we have d1 = d2 . The following theorem, establishes the existence and uniqueness of the greatest common divisor and provide an algorithm of how to find it. Theorem 12.2 (The Euclidean Algorithm) If a and b are two integers, not both zero, then there exists a unique positive integer d such that the two conditions (1) and (2) of Definition 12.1 are satisfied. Proof. Uniqueness: Let d1 and d2 be two positive integers that satisfy conditions (1) and (2). Then by (2) we can write d1 |d2 and d2 |d1 . Since d1 and d2 are both positive then Theorem 10.2 (d) implies that d1 = d2 . Existence: Without loss of generality, we may assume that b 6= 0. Note that if a = 0 then d = |b|. Indeed, |b| |0 and |b| |b. Moreover, if c is a common divisor of a and b then b = cq so that |b| = cq 0 . That is, c| |b|. So assume that a 6= 0. By the Division algorithm there exist unique integers q1 and r1 such that a = bq1 + r1 , 0 ≤ r1 < |b|. If r1 = 0 then as above, one can easily check that d = |b|. So assume that r1 6= 0. Using the Division algorithm for a second time to find unique integers q2 and r2 such that b = r 1 q2 + r 2 0 ≤ r 2 < r 1 . We keep this process going and eventually we will find integers rn and rn+1 such that rn−2 = rn−1 qn + rn , 0 ≤ rn < rn−1 and rn−1 = rn qn+1 . That is, rn is the last nonzero remainder in the process. By Theorem 12.1, we have (a, b) = (b, r1 ) = (r1 , r2 ) = · · · = (rn−1 , rn ) = rn . 2 Example 12.2 Performing the arithmetic for the Euclidean algorithm we have 1776 1492 284 72 68 = (1)(1492) + 284 = (5)(284) + 72 = (3)(72) + 68 = (1)(68) + 4 = 4(17) So (1776, 1492) = 4. An alternative proof for the existence of the greatest common divisor which does not provide a systematic way for finding (a, b) is given next. The theorem is important for its theoretical applications. Theorem 12.3 If a and b are two integers, not both zero, then there exist integers m and n such that (a, b) = ma + nb. That is, (a, b) can be expressed as a linear combination of a and b. Proof. Without loss of generality, we assume that b 6= 0. Let S = {xa + yb > 0 : x, y ∈ Z}. We first show that S 6= ∅. To see this, note that if b > 0 then b = 0a + (1)b ∈ S. If b < 0 then −b = 0a + (−1)b ∈ S. Note that 0 6∈ S. By Theorem 10.1, S has a smallest element d. Thus, d = ma + nb > 0 for some integers m and n. We will show that d = (a, b). Applying the Division algorithm we can find unique integers q and r such that a = dq + r with 0 ≤ r < d. From this equation we see that r = a − dq = a − (ma + nb)q = (1 − mq)a + (−nq)b If r > 0 then r ∈ S and r < d. This contradicts the definition of d. Therefore, r = 0 and this gives a = dq and hence d|a. A similar argument holds for d|b. Finally, if c is an integer such that c|a and c|b then a = cq and b = cq 0 . Thus, d = ma + nb = mcq + ncq 0 = c(mq + nq 0 ) This means that c|d. Thus, d = (a, b). This ends a proof of the Theorem. 3 Remark 12.1 The integers m and n in Theorem 12.3 are not unique. Indeed, (a, b) = ma + nb = ma + ab + nb − ab = (m + b)a + (n − a)b = m0 a + n0 b Example 12.3 From Example 12.2, we found that (1776, 1492) = 4. Let’s write this as a linear combination of 1776 and 1492. We use the equations in Example 12.2, beginning with 72 = (1)(68) + 4 and working backward one step at a time. 4 = 72 − (1)(68). Solve the equation 284 = (3)(72) + 68 for 68 and substitute in the previous equation and simplify to obtain 4 = 72 − (1)(284 − 3 · 72) = 72 · (4) − 284 Solve the equation 1492 = (5)(284) + 72 for 72 and substitute in the previous equation and simplify to obtain 4 = (1492 − 5 · 284) · 4 − 284 = 1492 · 4 − 21 · 284 Finally, solve the equation 1776 = 1492+284 for 284 and substitute to obtain 4 = 1492 · 4 − 21(1776 − 1492) = −21 · 1776 + 25 · 1492 Theorem 12.4 If a and b are integers, not both zero, then (a, b) = 1 if and only if ma+nb = 1 for some integers m and n. Proof. Suppose first that (a, b) = 1. By Theorem 12.3, there exist integers m and n such that ma + nb = 1. Conversely, suppose that ma+nb = 1 for some integers m and n. If d = (a, b) then d|a and d|b so d|(ma + nb) (Theorem 10.2 (a)(b)). That is, d|1, 1|d and d > 0 then by Theorem 10.2(d) we must have d = 1. 4 Definition 12.2 If a and b are integers such that (a, b) = 1 then we say that a and b are relatively prime. The next result, characterizes those elements of Zn that have multiplicative inverses. Theorem 12.5 [a] ∈ Zn has a multiplicative inverse if and only if (a, n) = 1. Proof. Suppose first that [a] has a multiplicative inverse [b] in Zn . Then [a] [b] = [ab] = [1]. This implies that ab ≡ 1(mod n). Therefore, ab = nq + 1 for some integer q. This last equality can be written in the form ba + (−q)n = 1. Suppose that d = (a, n). By Theorem 10.2(a)(b), d|1. Since 1|d then by Theorem 10.2(d), d = (a, n) = 1. Conversely, suppose that (a, n) = 1. Then by Theorem 12.4, there exist integers m and q such that ma + qn = 1. Thus, ma − 1 = (−q)n and hence ma ≡ 1(mod n). In terms of , we have [m] [a] = [1]. Thus, [a] has a multiplicative inverse in Zn . As a consequence of the above theorem we have Theorem 12.6 Every nonzero element of Zn has a multiplicative inverse if and only if n is a prime number. Thus, (Z∗n , ) is a group if and only if n is prime. Proof. Suppose first that [a] has a multiplicative inverse for all 1 ≤ a < n. Then by Theorem 12.5, (a, n) = 1 for 1 ≤ a < n. This is true only if n is prime. Conversely, suppose that n is prime then (a, n) = 1 for every 1 ≤ a < n. By Theorem 12.5, [a] has a multiplicative inverse for all 1 ≤ a < n. 5