Number Theory Learning Module 3 — The Greatest Common

advertisement

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 geometry, 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 gcd p a , b q

.

For example, the greatest common divisor of 168 and 120 is 24. Or, gcd p

168 , 120 q

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 : gcd p a , b q gcd p a , b q gcd p a , b q gcd p| a

|

,

| b

|q

(2.2)

We make the following convention when writing identities with gcds: we assume that all terms involved are welldefined. For example, in the expressions above, we are assuming that a and b are not both 0.

Created by L. Felipe Martins.

l.martins@csuohio.edu

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 gcd p a , 0 q

, 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 gcd p a , 0 q is simply the largest divisor of a , which is

| a

|

. That is: gcd p a , 0 q | 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:

gcd p

0 , 0 q 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 Section

3 .

Many facts about the gcd can be derived directly form the definition. Suppose that we want to show that gcd p a , b q gcd p c , d q

.

(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: gcd p a , b q gcd p a , a b q gcd p a b , b q gcd p a , b q gcd p a , a b q gcd p a b , b q gcd p a , b q gcd p a , na b q gcd p a nb , b q

(2.5)

(2.6)

(2.7)

Also, if b 0 : gcd p a , b q gcd p b , a mod b q

Proof.

Let’s first show that gcd p a , b q gcd p a , a b q

. Following the prescription above:

(2.8)

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 p a b q 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: gcd p a , b q gcd p a , b q gcd p a , a p b qq gcd p a , a b q

.

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 gcd p b , a mod b q gcd p b , r q gcd p b , a qb q gcd p b , p a qb q qb q gcd p b , a q gcd p a , b q

.

Created by L. Felipe Martins.

l.martins@csuohio.edu

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 3

3

31500 2

2

5 7

3

3

2

5

3 and

7 we can conclude that gcd p a , b q

3

2

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:

gcd p

46305 , 31500 q gcd p

31500 , 46305 mod 31500 q gcd p

31500 , 14805 q gcd p

14805 , 31500 mod 14805 q gcd p

14805 , 1890 q gcd p

1890 , 1575 q gcd p

1575 , 315 q gcd p

315 , 0 q

= gcd gcd gcd

315 p p p

1890

1575

315 ,

,

,

14805 mod 1890

1890 mod 1575

1575 mod 315 q q q

We conclude that gcd p

46305 , 31500 q

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 r

0 a and r

1 b.

2. For n

¥

1 , while r n

0 , let r n 1 r n 1 mod r n

.

Then, gcd p a , b q | r n 1

|

, that is, the last nonzero remainder in the chain of calculations.

Proof.

We start by observing that, since r n 1 no n such that r n is the remainder of r n 1 divided by r n

, we have

| r n 1

0, then we have generated an infinite decreasing sequence of positive integers:

|   | r n

|

. If there is

| r

1

| ¡ | r

2

| ¡ | r

3

| ¡

. . . , which is impossible. We conclude that there must be a n such that r n repeatedly:

0. For this n we have, applying identity gcd p a , b q gcd p r

0

, r

1 q gcd p r

1

, r

2 q gcd p r n 1

, r n q gcd p r n 1

, 0 q | r n 1

|

,

(2.8)

which finishes the proof.

(Notice a subtle point: the only reason we take the absolute value of r n 1 the very first step, in the case b 0 and a

 

0. An alternative is to let r

0 is to be correct if the algorithm stops in

| a

|

).

Example 3.2.

As another example, let’s compute gcd p

1225 , 351 q

. It is convenient to lay out the computations in a table. In each row, r n is the remainder of the division of the integers in the two previous rows.

4

5

6 n x n

0 1225

1 351

2 172

3 7

4

3

1

Created by L. Felipe Martins.

l.martins@csuohio.edu

License: http://creativecommons.org/licenses/by-nc-sa/3.0/us/

Number Theory

Learning Module 3 — The Greatest Common Divisor

4

Thus, gcd p

1225 , 351 q

1. This means that 1225 and 351 have no common factor greater than 1. In this case, we say that 1225 and 351 are relatively prime . We will have more to say about relatively prime integers in the next learning module.

4 Problems

1. Prove the identities in

(2.5) , (2.6)

and

(2.7)

that were not proved in the text.

2. Use Euclid’s algorithm to compute gcd p a , b q for each given pair of integers.

(a) a 196, b 385

(b) a 1755, b 375

(c) a 9261, b 2499

(d) a 313807, b 601859

3. The Fibonacci sequence is defined as follows:

F

1

1 , F

2

1 , F n

F n 1

F n 2 if n

¡

2 .

For example, F

3

F

2

F

1

1 1 2, F

4

F

3

F

2

2 1 3, F

4

F

3

F

2

3 2 5

(a) Compute F

5

, F

6

, F

7 and F

8

.

(b) Use Euclid’s algorithm to compute gcd p

F n

, F n 1 q for n 4 , 5 , 6 , 7.

(c) What can you observe from this calculation? Write a mathematical conjecture based in your observations.

(d) Prove your conjecture.

4. The method of computing the gcd using prime factorizations can be formalized as follows: Suppose that a and b have the prime factorizations: a p b p r

1

1 s

1

1 p r

2 p

2 s

2

2

. . .

p r n n

. . .

p s n n

(Zero exponents are allowed here.) Show that: where t i gcd p a , b q p t

1

1 p t

2

2

. . .

p t n n

, min t r i

, s i u

, that is, t i is the large of the two integers r i

, s i

.

5. Determine if each of the statements below are true or false, providing a proof or counterexample according to each case. In each statement, assume that variables represent arbitrary integers for which all gcds are well defined.

(a) gcd p a , b q gcd p a b , a b q

(b) gcd p gcd p a , b q

, c q gcd p a , gcd p b , c qq

.

(c) gcd p a n

, b n q gcd p a , b q n

, where n is a positive integer.

(d) gcd p ac , bc q | c

| gcd p a , b q

.

Created by L. Felipe Martins.

l.martins@csuohio.edu

License: http://creativecommons.org/licenses/by-nc-sa/3.0/us/

Number Theory

Learning Module 3 — The Greatest Common Divisor

5

(e) a and a 1 are always relatively prime.

(f) If p is prime, a and a p are always relatively prime.

6. Show that, if p is prime, then for any integer a we have: gcd p p , a q

# p if p divides a ;

1 otherwise

7. This problem presents yet another proof that there are infinitely many primes.

(a) Let p

1

, p

2

, . . . , p n be prime numbers and k

1

, k

2

, . . .

k n integers of the form: p e

1

1 p e

2

2

. . .

p e n n with e i

¤ be arbitrary positive integers. What is the number of k i for i 1 , 2 , . . . , n .

(b) Let M be an integer strictly larger than the number you computed in the previous item. Show that there is a prime number in r

2 , M s that is distinct of all p i for i 1 , 2 , . . . , n . Explain why this implies that there are infinitely many primes.

8. In this problem, we will explore an alternative algorithm for computation of the gcd, called the binary gcd algorithm . Suppose that a and b are nonnegative integers, not both 0. Then, to compute gcd p a , b q

, proceed as follows.

(a) Let m 1

(b) While b 0, do: i. If a

  b , exchange the values of a and b .

ii. Then, select one of the following actions:

A. If a and b are both even, then replace a by a

{

2, b by b

{

2 and multiply m by 2.

B. If a is even and b is odd, then, replace a by a

{

2.

C. If a is odd and b is even, then replace b by b

{

2.

D. If a and b are both odd, replace a by p a b q{

2.

(c) When you reach a point where b 0, then ma is the gcd of the two initial numbers..

Do the following:

(a) Use this algorithm to compute the gcd of the pairs of numbers given in Problem 2.

(b) Prove that the algorithm always finishes and does indeed compute the gcd p a , b q

.

Created by L. Felipe Martins.

l.martins@csuohio.edu

License: http://creativecommons.org/licenses/by-nc-sa/3.0/us/

Download