Section 11.4 Greatest Common Divisors and the Integers Modulo
In this section introduce the greatest common divisor operation, and introduce an important family of concrete groups, the integers modulo
Subsection 11.4.1 Greatest Common Divisors
We start with a theorem about integer division that is intuitively clear. We leave the proof as an exercise.
Note 11.4.2.
The division property says that if is divided by you will obtain a quotient and a remainder, where the remainder is less than This is a fact that most elementary school students learn when they are introduced to long division. In doing the division problem you obtain a quotient of 20 and a remainder of 46. This result could either be written or The latter form is how the division property is normally expressed in higher mathematics.
We now remind the reader of some interchangeable terminology that is used when i. e., All of the following say the same thing, just from slightly different points of view.
- divides
- multiple
- factor
- divisor
Caution: Don’t confuse the “divides” symbol with the “divided by” symbol. The former is vertical while the latter is slanted. Notice however that the statement is related to the fact that is a whole number.
Definition 11.4.4. Greatest Common Divisor.
A little simpler way to think of is as the largest positive integer that is a divisor of both and However, our definition is easier to apply in proving properties of greatest common divisors.
For small numbers, a simple way to determine the greatest common divisor is to use factorization. For example if we want the greatest common divisor of 660 and 350, you can factor the two integers: and Single factors of 2 and 5 are the only ones that appear in both factorizations, so the greatest common divisor is
Some pairs of integers have no common divisors other than 1. Such pairs are called relatively prime pairs.
Definition 11.4.5. Relatively Prime.
For example, and are relatively prime. Notice that neither 128 nor 135 are primes. In general, and need not be prime in order to be relatively prime. However, if you start with a prime, like 23, for example, it will be relatively prime to everything but its multiples. This theorem, which we prove later, generalizes this observation.
Theorem 11.4.6.
Subsection 11.4.2 The Euclidean Algorithm
As early as Euclid’s time it was known that factorization wasn’t the best way to compute greatest common divisors.
To compute we divide into and get a remainder such that By the property above, We repeat the process until we get zero for a remainder. The last nonzero number that is the second entry in our pairs is the greatest common divisor. This is inevitable because the second number in each pair is smaller than the previous one. Table 11.4.7 shows an example of how this calculation can be systematically performed.
Here is a Sage computation to verify that At each line, the value of is divided by the value of The quotient is placed on the next line along with the new value of which is the previous and the remainder, which is the new value of Recall that in Sage,
a%b
is the remainder when dividing b
into a
.xxxxxxxxxx
a=99
b=53
while b>0:
print('computing gcd of '+str(a)+' and '+str(b))
[a,b]=[b,a%b]
print('result is '+str(a))
Investigation 11.4.1.
If you were allowed to pick two integers less than 100, which would you pick in order to force Euclid to work hardest? Here’s a hint: The size of the quotient at each step determines how quickly the numbers decrease.
Solution.
If quotient in division is 1, then we get the slowest possible completion. If then working backwards, each remainder would be the sum of the two previous remainders. This described a sequence like the Fibonacci sequence and indeed, the greatest common divisor of two consecutive Fibonacci numbers will take the most steps to reach a final value of 1.
For fixed values of and consider integers of the form where and can be any two integers. For example if = 36 and = 27, some of these results are tabulated below with values along the left column and the values on top.

Do you notice any patterns? What is the smallest positive value that you see in this table? How is it connected to 36 and 27?
Theorem 11.4.9. Bézout’s lemma.
Proof.
If since and we know that for any integers and so can’t be less than To show that is exactly the least positive value, we show that can be attained by extending the Euclidean Algorithm. Performing the extended algorithm involves building a table of numbers. The way in which it is built maintains an invariant, and by The Invariant Relation Theorem, we can be sure that the desired values of and are produced.
To illustrate the algorithm, Table 11.4.10 displays how to compute In the column, you will find 152 and 53, and then the successive remainders from division. So each number in after the first two is the remainder after dividing the number immediately above it into the next number up. To the left of each remainder is the quotient from the division. In this case the third row of the table tells us that The last nonzero value in is the greatest common divisor.
152 | 1 | 0 | |
53 | 0 | 1 | |
2 | 46 | 1 | |
1 | 7 | 3 | |
6 | 4 | 7 | |
1 | 3 | 23 | |
1 | 1 | 15 | |
3 | 0 | 152 |
The “ ” and “ ” columns are new. The values of and in each row are maintained so that is equal to the number in the column. Notice that
The next-to-last equation is what we’re looking for in the end! The main problem is to identify how to determine these values after the first two rows. The first two rows in these columns will always be the same. Let’s look at the general case of computing If the and values in rows and are correct, we have
In addition, we know that
If you substitute the expressions for and from (A) into this last equation and then collect the and terms separately you get
or
Look closely at the equations for Their forms are all the same. With a little bit of practice you should be able to compute and values quickly.
Subsection 11.4.3 Modular Arithmetic
We remind you of the relation on the integers that we call Congruence Modulo . If two integers, and differ by a multiple of we say that they are congruent modulo denoted For example, because which is a multiple of 5.
Definition 11.4.12. The Integers Modulo .
Definition 11.4.13. Modular Addition.
Definition 11.4.14. Modular Multiplication.
Note 11.4.15.
- The result of doing arithmetic modulo
is always an integer between 0 and by the Division Property. This observation implies that is closed under modulo arithmetic. - It is always true that
and For example, and - One interpretation of
is that each element is a representative of its equivalence class with respect to congruence modulo For example, if the number in really represents all numbers in In doing modular arithmetic, we can temporarily replace elements of with other elements in their equivalence class modulo
Example 11.4.16. Some Examples.
- We are all somewhat familiar with
since the hours of the day are counted using this group, except for the fact that 12 is used in place of 0. Military time uses the mod 24 system and does begin at 0. If someone started a four-hour trip at hour 21, the time at which she would arrive is If a satellite orbits the earth every four hours and starts its first orbit at hour 5, it would end its first orbit at time Its tenth orbit would end at hours on the clock - Virtually all computers represent unsigned integers in binary form with a fixed number of digits. A very small computer might reserve seven bits to store the value of an integer. There are only
different values that can be stored in seven bits. Since the smallest value is 0, represented as 0000000, the maximum value will be represented as 1111111. When a command is given to add two integer values, and the two values have a sum of 128 or more, overflow occurs. For example, if we try to add 56 and 95, the sum is an eight-digit binary integer 10010111. One common procedure is to retain the seven lowest-ordered digits. The result of adding 56 and 95 would be Integer arithmetic with this computer would actually be modulo 128 arithmetic.
Subsection 11.4.4 Properties of Modular Arithmetic
Theorem 11.4.17. Additive Inverses in .
Proof.
Addition modulo is always commutative and associative; 0 is the identity for and every element of has an additive inverse. These properties can be summarized by noting that for each is a group.
Definition 11.4.18. The Additive Group of Integers Modulo .
The Additive Group of Integers Modulo is the group with domain and with the operation of mod addition. It is denoted as
Notice that the algebraic properties of and on are identical to the properties of addition and multiplication on
Notice that a group cannot be formed from the whole set with mod multiplication since zero never has a multiplicative inverse. Depending on the value of there may be other numbers that will be excluded.
Definition 11.4.19. The Multiplicative Group of Integers Modulo .
The Multiplicative Group of Integers Modulo is the group with domain and with the operation of mod multiplication. It is denoted as
Example 11.4.20. Some operation tables.
Here are examples of operation tables for modular groups. Notice that although 8 is greater than 5, the two groups and both have order 4. In the case of since 5 is prime all of the nonzero elements of are included. Since 8 isn’t prime we don’t include integers that share a common factor with 8, the even integers in this case.
0 | 0 | 1 | 2 | 3 | 4 |
1 | 1 | 2 | 3 | 4 | 0 |
2 | 2 | 3 | 4 | 0 | 1 |
3 | 3 | 4 | 0 | 1 | 2 |
4 | 4 | 0 | 1 | 2 | 3 |
1 | 1 | 2 | 3 | 4 |
2 | 2 | 4 | 1 | 3 |
3 | 3 | 1 | 4 | 2 |
4 | 4 | 3 | 2 | 1 |
1 | 1 | 3 | 5 | 7 |
3 | 3 | 1 | 7 | 5 |
5 | 5 | 7 | 1 | 3 |
7 | 7 | 5 | 3 | 1 |
Computing Modular Multiplicative Inverses. Unlike the nice neat formula for additive inverses mod multiplicative inverses can most easily computed by applying Bézout’s lemma. If is an element of the group then by definition and so there exist integers and such that They can be computed with the Extended Euclidean Algorithm.
Since might not be in you might need take the remainder after dividing it by Normally, that involves simply adding to
Subsection 11.4.5 SageMath Note - Modular Arithmetic
Sage inherits the basic integer division functions from Python that compute a quotient and remainder in integer division. For example, here is how to divide 561 into 2017 and get the quotient and remainder.
xxxxxxxxxx
a=2017
b=561
[q,r]=[a//b,a%b]
[q,r]
In Sage, is the greatest common divisor function. It can be used in two ways. For the gcd of 2343 and 4319 we can evaluate the expression If we are working with a fixed modulus that has a value established in your Sage session, the expression to compute the greatest common divisor of and any integer value The extended Euclidean algorithm can also be called upon with
xxxxxxxxxx
a=2017
b=561
print(gcd(a,b))
print(xgcd(a,b))
Sage has some extremely powerful tool for working with groups. The integers modulo are represented by the expression and the addition and multiplications tables can be generated as follows.
xxxxxxxxxx
R = Integers(6)
print(R.addition_table('elements'))
print(R.multiplication_table('elements'))
Once we have assigned a value of we can do calculations by wrapping around the integers 0 through 5. Here is a list containing the mod 6 sum and product, respectively, of 5 and 4:
xxxxxxxxxx
[R(5)+R(4), R(5)*R(4)]
Generating the multiplication table for the family of groups takes a bit more code. Here we restrict the allowed inputs to be integers from 2 to 64.
xxxxxxxxxx
def U_table(n):
if n.parent()!=2.parent() or n < 2 or n > 64:
return "input error/out of range"
R=Integers(n)
els=[]
for k in filter(lambda k:gcd(n,k)==1,range(n)):
els=els+[str(k)]
return R.multiplication_table(elements=els,names="elements")
U_table(18)
Exercises 11.4.6 Exercises
1.
Determine the greatest common divisors of the following pairs of integers without using any computational assistance.
and and and- 12112 and 0
Answer.
- 12112
2.
3.
Answer.
- 2
- 5
- 0
- 0
- 2
- 2
- 1
- 3
- 0
4.
5.
Answer.
- 1
- 1
where
6.
When defining notice that we could define this operation on all integers, but we restricted the set to to satisfy the properties of a group. Can you explain what goes wrong if we define on all of the integers?
7.
A student is asked to solve the following equations under the requirement that all arithmetic should be done in List all solutions.
Answer.
Since the solutions, if they exist, must come from substitution is the easiest approach.
- 1 is the only solution, since
and - No solutions, since
and
8.
Determine the solutions of the same equations as in Exercise 5 in
9.
- Write out the operation table for
on and convince your self that this is a group. - Let
be the elements of that have inverses with respect to Convince yourself that is a group under
10.
Prove the division property, Theorem 11.4.1.
Hint.
Prove by induction on that you can divide any positive integer into That is, let be “For all greater than zero, there exist unique integers and such that .” In the induction step, divide into
11.
Suppose such where and are integer constants. Furthermore, assume that and Find a formula for and also find a formula for the inverse of
Solution.
The given conditions can be converted to a system of linear equations:
If we subtract the first equation from the second, we get This implies that and To get a formula for the inverse of we solve for using the fact that the multiplicative inverse of 10 (mod 17) is 12.
Therefore
12.
Solution.
This system is a monoid with identity 6 (surprise!). However it is not a group since 0 has no inverse.
13.
Solution.
14.
15.
16.
It was observed above that in doing modular arithmetic, one can replace an element of with any other element of its equivalence class modulo For example, if one is computing the alternative to multiplying time and then dividing by to get the remainder in we can replace with and get a product of which is conguent of Use this “trick” to compute the following without the use of a calculator.
- The solution to
17.
You have attempted of activities on this page.