Number Theory Learning Module 3 — the Greatest Common Divisor 1
Total Page:16
File Type:pdf, Size:1020Kb
Number Theory Learning Module 3 — The Greatest Common Divisor 1 1 Objectives. • Understand the definition of greatest common divisor (gcd). • Learn the basic the properties of the gcd. • Understand Euclid’s algorithm. • Learn basic proofing techniques for greatest common divisors. 2 The Greatest Common Divisor Classical Greek mathematics concerned itself mostly with geometry. The notion of measurement is fundamental to ge- ometry, and the Greeks were the first to provide a formal foundation for this concept. Surprisingly, however, they never used fractions to express measurements (and never developed an arithmetic of fractions). They expressed geometrical measurements as relations between ratios. In numerical terms, these are statements like: 168 is to 120 as 7 is to 4, (2.1) which we would write today as 168{120 7{5. Statements such as (2.1) were natural to greek mathematicians because they viewed measuring as the process of finding a “common integral measure”. For example, we have: 168 24 ¤ 7 120 24 ¤ 5; so that we can use the integer 24 as a “common unit” to measure the numbers 168 and 120. Going back to our example, notice that 24 is not the only common integral measure for the integers 168 and 120, since we also have, for example, 168 6 ¤ 28 and 120 6 ¤ 20. The number 24, however, is the largest integer that can be used to “measure” both 168 and 120, and gives the representation in lowest terms for their ratio. This motivates the following definition: Definition 2.1. Let a and b be integers that are not both zero. Then, the greatest common divisor (gcd) of a and b is the largest integer that divides both a and b, and is denoted by gcdpa;bq. For example, the greatest common divisor of 168 and 120 is 24. Or, gcdp168;120q 24. This can be verified from the definition by listing all positive divisors of 168 and 120: Divisors of 168 : 1, 2, 3, 4, 6, 7, 8, 12, 14, 21, 24, 28, 42, 56, 84, 168 Divisors of 120 : 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24, 30, 40, 60, 120 We can see that 24 is the largest integer that is in both lists. An important observation is that the gcd of two integers is always positive. The gcd, however, is defined for negative integers as well. In fact, using the fact that the set of divisors of a and ¡a are identical, it easy to see that for, all integers a, b: gcdpa;bq gcdpa;¡bq gcdp¡a;bq gcdp|a|;|b|q (2.2) We make the following convention when writing identities with gcds: we assume that all terms involved are well- defined. For example, in the expressions above, we are assuming that a and b are not both 0. Created by L. Felipe Martins. [email protected] License: http://creativecommons.org/licenses/by-nc-sa/3.0/us/ Number Theory Learning Module 3 — The Greatest Common Divisor 2 By the way, there is a subtle point about Definition 2.1. Whenever we talk about the largest integer satisfying a property, it is important to make sure the set of integers in question is bounded from above. In our case, however, everything is fine, since any divisor of a nonzero integer a less than or equal to |a|, so that the set of divisors of a is finite. Thus, if at least one of a and b are not zero, the set of common divisors is finite, and has a largest element. This brings the question of what happens when one of the integers a, b is zero. What is gcdpa;0q, for a 0? Well, let’s use the definition. This is the largest integer that divides both a and 0. However, every integer divides zero, so gcdpa;0q is simply the largest divisor of a, which is |a|. That is: gcdpa;0q |a| if a 0: (2.3) The situation is different if both number are zero: then, the set of common divisors consists of all integers, and has no largest element. This is why the case a b 0 is explicitly excluded from Definition 2.1. Always remember this: gcdp0;0q is not defined. The reader might find it silly to be talking so much about the special case of one of the terms in the gcd being 0. This little case turns out to be extremely important, as we will see in Section3. Many facts about the gcd can be derived directly form the definition. Suppose that we want to show that gcdpa;bq gcdpc;dq: (2.4) (Whenever we write an expression with gcd’s, we assume that all terms are well-defined. Here, for example we assume ab 0 and cd 0.) One technique that we can use is the following: 1. Assume first that q is a common divisor of a and b. Show that q is a common divisor of c and d. 2. Then assume that q is a common divisor of c and d. Show that q is a common divisor of a and b. In other words, we prove that the set of common divisors of a and b is identical to the set of common divisors of c and d. This proving technique is illustrated in the following result. Theorem 2.2. Let a and b and n be integers. Then: gcdpa;bq gcdpa;a bq gcdpa b;bq (2.5) gcdpa;bq gcdpa;a ¡ bq gcdpa ¡ b;bq (2.6) gcdpa;bq gcdpa;na ¨ bq gcdpa ¨ nb;bq (2.7) Also, if b 0: gcdpa;bq gcdpb;a mod bq (2.8) Proof. Let’s first show that gcdpa;bq gcdpa;a bq. Following the prescription above: 1. Let q be a common divisor of a and b. Then q divides a b. So, q is a common divisor of a and a b. 2. Let q be a common divisor of a and a b. Then q divides pa bq¡a b, so that q is a common divisor of a and b. We could prove the other identities in (2.5) and (2.6) by the same method. However, it is faster to simply use what we have already learned. For example, we have: gcdpa;bq gcdpa;¡bq gcdpa;a p¡bqq gcdpa;a ¡ bq: Identity (2.7) is left for the reader to prove in the exercises. Finally, (2.8) follows from (2.7). If we let q a div b and r a mod b, then a qb r so that r a ¡ qb. Then gcdpb;a mod bq gcdpb;rq gcdpb;a ¡ qbq gcdpb;pa ¡ qbq qbq gcdpb;aq gcdpa;bq. Created by L. Felipe Martins. [email protected] License: http://creativecommons.org/licenses/by-nc-sa/3.0/us/ Number Theory Learning Module 3 — The Greatest Common Divisor 3 3 Euclid’s Algorithm One way to compute the gcd of two numbers is to use their prime factorization. For example, from: 46305 33 ¤ 5 ¤ 73 and 31500 22 ¤ 32 ¤ 53 ¤ 7 we can conclude that gcdpa;bq 32 ¤ 5 ¤ 7 315. This is not, however, the most efficient way of computing the gcd for large numbers. A much better algorithm was discovered by the Euclid. The idea is to repeatedly use identity (2.8), reducing with each step the size of the numbers: gcdp46305;31500q gcdp31500;46305 mod 31500q gcdp31500;14805q gcdp14805;31500 mod 14805q gcdp14805;1890q gcdp1890;14805 mod 1890q gcdp1890;1575q gcdp1575;1890 mod 1575q gcdp1575;315q gcdp315;1575 mod 315q gcdp315;0q = 315 We conclude that gcdp46305;31500q 315. Notice that in the last line we used (2.3). (We warned that this special case would be important, remember?) The next result shows that the method works in general. Theorem 3.1 (Euclid’s algorithm). Let a, b be two integers, not both zero. The gcd of a and b can be found by the following algorithm: 1. Let r0 a and r1 b. 2. For n ¥ 1, while rn 0, let rn 1 rn¡1 mod rn. Then, gcdpa;bq |rn¡1|, that is, the last nonzero remainder in the chain of calculations. Proof. We start by observing that, since rn 1 is the remainder of rn¡1 divided by rn, we have |rn 1| |rn|. If there is no n such that rn 0, then we have generated an infinite decreasing sequence of positive integers: |r1| ¡ |r2| ¡ |r3| ¡ :::; which is impossible. We conclude that there must be a n such that rn 0. For this n we have, applying identity (2.8) repeatedly: gcdpa;bq gcdpr0;r1q gcdpr1;r2q ¤¤¤ gcdprn¡1;rnq gcdprn¡1;0q |rn¡1|; which finishes the proof. (Notice a subtle point: the only reason we take the absolute value of rn¡1 is to be correct if the algorithm stops in the very first step, in the case b 0 and a 0. An alternative is to let r0 |a|). Example 3.2. As another example, let’s compute gcdp1225;351q. It is convenient to lay out the computations in a table. In each row, rn is the remainder of the division of the integers in the two previous rows. n xn 0 1225 1 351 2 172 3 7 4 4 5 3 6 1 Created by L. Felipe Martins. [email protected] License: http://creativecommons.org/licenses/by-nc-sa/3.0/us/ Number Theory Learning Module 3 — The Greatest Common Divisor 4 Thus, gcdp1225;351q 1. This means that 1225 and 351 have no common factor greater than 1.