Modular Arithmetic Notes
Modular Arithmetic Notes
Introduction
Modular arithmetic can be thought of as a way to deal with repetitions. Actually, modular
arithmetic is used in many areas of mathematics, but for this class, it is best to think of
repetitions.
I may have mentioned that math is like creating your own playground, and then seeing what
happens when you play in it. I will show you this approach for modular arithmetics.
What we will do is we will use the integers and place them in modules. First, we choose how
many modules there are, and we will call this the modulus. So, for example, if we have a
modulus of 5, then there are 5 modules. Each integer will go into exactly one of these
modules. For now, let’s label the modules as A, B, C, D, and E.
To simplify matters, we will deal with negative integers later on. Let’s just focus on non-
negative integers and place them in the bins (i.e. modules). We will start with the smallest
non-negative integer, which is zero, and place it in module A. The next integer is one, and we
place this in the next module, which is B. The next integer, two, goes into the next module, C,
and following this pattern, we have that 3 goes into module D, and 4 goes into module E.
A B C D E
0 1 2 3 4
The above diagram illustrates what we have so far. Now, there’s a small problem. The next
integer is 5, but there is no next module. So, for the module, we start from the beginning.
Thus, 5 will go into module A; 6 into B; 7 into C; 8 into D; and 9 into E. Again, since E is the last
module, the next integer, 10, will go into the first module A. We repeat this pattern for all the
next integers. The following diagram illustrates what numbers go into which module, up to 39.
A B C D E
0, 5, 10, 15, 1, 6, 11, 16, 2, 7, 12, 17, 3, 8, 13, 18, 4, 9, 14, 19,
20, 25, 30, 35 21, 26, 31, 36 22, 27, 32, 37 23, 28, 33, 38 24, 29, 34, 39
I have purposely made the diagram this way to show you that in math, there is creativity. It
might not be clear what’s going on, so instead of showing you the modules and which number
goes into which modules, let’s arrange the diagram a little differently:
Modules A B C D E
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
15 16 17 18 19
Numbers
20 21 22 23 24
25 26 27 28 29
30 31 32 33 34
35 36 37 38 39
Can you tell what modules should the following numbers go to?
(1) 43
(2) 79
(3) 152
(4) 828
NOTE: Before you get used to using the letters to label the modules, we will rename the
modules. Instead of alphabets, we use the smallest non-negative integer in the module to
label it. Thus, A becomes 0, B becomes 1, C becomes 2, D becomes 3, and E becomes 4. So, in
the new labelling, the answers would be 3, 4, 2, and 3.
Using the new naming scheme for the modules, the previous table above becomes:
Modules 0 1 2 3 4
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
15 16 17 18 19
Numbers
20 21 22 23 24
25 26 27 28 29
30 31 32 33 34
35 36 37 38 39
You should observe that the numbers in a module differ by a multiple of the modulus (recall
that the modulus is the total number of modules). Thus, in the example, you’ll see that to get
from one number in the module to another number in the same module, you’ll just need to
add or subtract by 5 enough times (since 5 is the modulus). For example, in module 2, to get
from 12 to 27, you just need to add 5 three times. Another example, in module 3, to get from
38 to 3, you will subtract by 5 seven times.
This happens because when we were placing the numbers into the modules (i.e. bins), once
we reached the last module, we started back at the beginning. Thus, to get the next number in
the same module, you would just add by the modulus (i.e. the number of bins).
Now, let’s include the negative integers. You’ll notice that in the placement of the numbers
into the modules, we used the next greater integer and placed it in the next module. In the
examples, we started at 0 and moved to the next integer. Consider what would happen if we
started at 10. After placing it in the correct module, instead of dealing with the next integer
11, we’ll deal with the previous integer 9. In this case, it would go to the previous module
(note that if there is no more previous module, then it goes to the last module). Continuing
this idea of going backwards, you can develop a table with negative integers included.
Thus, using our previous example of 5 modules, the following table shows where some of the
negative integers would be placed:
Modules 0 1 2 3 4
–20 –19 –18 –17 –16
–15 –14 –13 –12 –11
–10 –9 –8 –7 –6
–5 –4 –3 –2 –1
Numbers
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
15 16 17 18 19
Great! We’re as good as done with placing all the integers into modules. Obviously, we can’t
physically do it for ALL the integers, but we have an understanding of how to build on it, and
some properties that arise due to how we built it.
Now, there’s one more thing we need before we can look at the arithmetic part. We want to
think of numbers that are in the same module as essentially being the same. Why would we do
this? Well, there are many applications for this, but a typical example is when you consider
that there are 24 hours in a day. You know that after 24 hours, you’ll end up with the same
time, although a different day. In some cases, you’re more concerned about just the time, so
modular arithmetic can help with this.
So, since we want numbers in the same module to be treated as if they are the same, we say
that they are congruent. To make a formal definition of congruent numbers, we will also use
the property that numbers in a module differ by a multiple of the modulo.
DEFINITION
Given an integer n > 1, called the modulus, two integers are said to be congruent modulo n, if
n is a divisor of their difference (i.e., if there is an integer k such that a – b = kn).
* This definition was taken from https://en.wikipedia.org/wiki/Modular_arithmetic.
Symbolically, if two numbers a and b are congruent in modulo n, we write this as:
a ≡ b mod n
or
a ≡ b (mod n)
or
( a ≡ b ) mod n
and we say that a is congruent to b modulo n. The parenthesis are sometimes used to avoid
ambiguity in more complicated expressions or exquations.
Let’s see how we use this definition. Let’s say the modulo is 27, and we want to know if 3,592
belongs to the same module as 485. Well, numbers in the same module are congruent, so let’s
use the definition to check if the difference is divisible by the modulo.
Difference:
3,592 – 485 = 3,107
Unfortunately, for larger modulo, this process is still tedious. The good news is there’s an
easier way. Let’s go back to this table:
Modules 0 1 2 3 4
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
15 16 17 18 19
Numbers
20 21 22 23 24
25 26 27 28 29
30 31 32 33 34
35 36 37 38 39
Before we do anything, we will make another change. Typically, mathematicians do not call
the modules as “modules”. A module is usually referred to as an equivalence class or
congruence class. Let’s update the table with this change. We call it an equivalence class
because the items in the class are defined to be equivalent in some way (there are other
technicalities involved, but that’s the general idea). The table below reflects this change.
Equivalence
0 1 2 3 4
Class
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
15 16 17 18 19
Numbers
20 21 22 23 24
25 26 27 28 29
30 31 32 33 34
35 36 37 38 39
We will also change how we called the labels for the equivalence class.
DEFINITION
The residue of an integer is the smallest non-negative integer in the equivalence class that the
integer belongs to. In other words, the residue of an integer is the smallest non-negative
integer that it is congruent to.
Thus, we will use residues to refer to an equivalence class. That is, instead of talking about the
labels of modules, we will now talk about the residues of equivalence classes. Also,
congratulations! You are now using standard math terminology.
*Before we proceed, what are the possible residues if the modulo is some number n? Try a
few different moduli and list the possible residues. You should notice that if the modulus is
some number n, then the possible residues are 0, 1, 2, 3, 4, … , n – 3, n – 2, and n – 1. For
example, if the modulus is 9, then the possible residues are 0, 1, 2, 3, 4, 5, 6, 7, and 8.
Continuing, remember, the modulo is 5. Pick any number in the table and then divide it by 5
(the modulo). What’s the remainder? Try this for a few other numbers. You should observe
that the remainder is actually the residue of the equivalence class that the number is in. For
example, the remainder when you divide 39 by 5 is 4, and the equivalence class that 39 is in
also has a residue of 4.
***** OPTIONAL READING FOR THOSE WHO FORGOT HOW TO GET THE REMAINDER. *****
***** YOU MAY SKIP THIS PART IF YOU KNOW HOW TO GET THE REMAINDER. *****
To determine the remainder, first apply the division. Make sure your result is either a mixed
fraction or a decimal. It should NOT be an improper fraction. Note the whole part of the result.
The remainder will be the when the product of the noted whole part and divisor is subtracted
FROM the dividend.
Example: To get the remainder of 5,423,473 divided by 6,347, first do the division:
Then, note that the whole part is 854 (basically ignore the decimal part, if your answer is
showing a mixed fraction, ignore the fraction).
Lastly, subtract FROM the dividend (5,423,473) the product of the noted whole part (854) and
the divisor (6,347):
The result is the remainder. So, the remainder of 5,423,473 divided by 6,347 is 3,135.
Another example with less explanation: Determine the remainder of 9,845 divided by 51.
9,845 ÷ 51 = 193.039…
9,845 – ( 51 × 193 ) = 2
The remainder is 2.
There are other ways to get the remainder, and some may be considered faster, but this is the
most consistent.
Also, observe that what you are doing can be interpreted in terms of what we are doing. The
dividend is the number we are looking at, and the divisor is the modulus. So, you’re actually
subtracting a multiple of the modulus from the number, and the result is already the residue.
So, going back to our large numbers of 3,592 and 485 in modulo 27, we have already
established that they don’t belong in the same equivalence class. Which equivalence class do
they belong to? I will rephrase this question so that we can minimize the use of the word
“equivalence class”. The reason for this is the idea of the numbers being in an equivalence
class is not as important (at least for this class) as the properties for being in an equivalence
class. We will make use of the definition for residue, and instead of asking about the
equivalence class, we will simply ask what are the residues of the numbers 3,592 and 485 in
modulo 27?
Let’s start with the residue of 485 in modulo 27. From the previous observation, we just need
to get the remainder when you divide 485 by 27. The answer is 26. Thus, the residue of 485 in
modulo 27 is 26. Thus, we can write this as:
485 ≡ 26 mod 27
By similar fashion, you should get that the residue of 3,592 in modulo 27 is 1. Thus, we can
write this as:
3,592 ≡ 1 mod 27
Disclaimer! Depending on how you were taught remainders, this method is only guaranteed
for non-negative integers. When dividing a negative integer, the method you were taught
might actually result in a negative remainder. Thus, you may think of the residue as the
positive remainder.
The last thing to take care of are negative integers. Before we begin, so that we are on the
same page, let’s take a look at multiplication.
Recall that when you multiply two numbers, if their signs are different, then the result is
negative, but if their signs are the same, then the result is positive.
Examples:
Now, we make use of one of the definitions of division, which is that dividing by the divisor is
equivalent to the same as multiplying by the reciprocal of the divisor, as long as the divisor
isn’t zero. Don’t worry if this confuses you, the key part is that division is essentially a
multiplication.
Alright, since division is equivalent to multiplication, that means when we divide a negative
number by a positive number, the answer is negative.
So, if you use the method of long division, what you will do is divide as if both the numbers are
positive, then change the sign of your answer, including the sign of the remainder. So, the
remainder will also be negative (of course, if the remainder is zero, then there is no sign
associated with it)
Okay, so, that’s what we’ll use to deal with negative integers.
Equivalence
0 1 2 3 4
Class
–30 –29 –28 –27 –26
Numbers
–25 –24 –23 –22 –21
–20 –19 –18 –17 –16
–15 –14 –13 –12 –11
–10 –9 –8 –7 –6
–5 –4 –3 –2 –1
0 1 2 3 4
5 6 7 8 9
If you go back to our example of – 16 ÷ 5, remember our answer was –3 remainder –1. Notice
that –16 and –1 both belong to the equivalence class 4.
Try a few other numbers. For example, –28 ÷ 5 results in –5 remainder –3. Again, –28 and the
remainder –3 are both in the same equivalence class.
Thus technically, the remainder will always be in the same equivalence class, the only problem
is that the remainder is not always a residue. So, how do we get the residue? Well, remember
that numbers in the same equivalence class differ by a multiple of the modulo. The residue is
nonnegative, right? But we have a negative remainder. What happens if you add the modulo
to the negative remainder? The result will still be in the same equivalence class, and it should
now be nonnegative.
So, looking at –16. From what we did previously, the remainder is –1. If you add 5 to –1, you’ll
get 4, which is a residue in modulo 5.
Likewise, for –28, from what we did previously, the remainder is –3. Add the modulo 5 to the
remainder –3, and you get 2, which is the residue.
In summary, when dealing with negative integers, simply treat it as positive and determine the
remainder. Then, make that remainder negative and add the modulus to it (this is actually the
same as doing the modulus minus the computed remainder).
We’re done with building our modular system. We have made enough to now deal with the
arithmetic part. The best part is, for addition, subtraction, and multiplication, modular
arithmetic works the same as the usual arithmetic, except there are two significant
differences.
First, in modular arithmetic, numbers in the same equivalence class can be substituted with
each other since they are considered the “same” (remember, they are in the same equivalence
class, so they are considered equivalent or congruent).
Second, answers are typically shown as residues. This is done so that it’s easy to discuss results
between different people (their answers might be different numbers, but are in the same
equivalence class. By showing results as residues, they don’t need to take the additional step
of verifying if their answers are indeed in the same equivalence class since there is only one
residue in each equivalence class).
Since numbers in the same equivalence class are considered the “same”, we can substitute a
number with any number in the same equivalence class. So, before applying the operations of
addition, subtraction, or multiplication, we may apply the appropriate substitution.
Now, to be clear, there are many ways to solve this. In fact, you may add the numbers first,
and then determine the residue of the resulting sum. In this way, you get the following:
As mentioned before, you may also substitute by other numbers in the same equivalence
class. Depending on the problem, you may take creative license as to what number (in the
same equivalence) to use. But, in general, a good place to start is with the residue. Thus, with
this in mind, the same question can be solved the following way also:
Thus, the answer is 4,835, and this is the same answer we got using the previous method. Just
note that in this case, we were fortunate enough that after applying the operations, the
resulting sum was already a residue. This is not always the case.
Some of you might have also observed that the first way seems to be faster than the second
way. In fact, that is correct! But, depending on the operations involved, sometimes the second
way is more convenient. The following example highlights this.
Go ahead and try to solve that product in your calculator. You will encounter one of the
limitations of basic scientific calculators, namely that the amount of numbers they can show is
limited. The calculator shows you part of the answer in scientific notation (go ahead and
review that if you’ve forgotten, as you will probably use it in your other science classes).
Your calculator will probably show something like “6.766805604 × 1017”. Note that there are
other numbers, but your calculator can’t show them due to limitations on its display and
computing capabilities. Fortunately, your calculator may be using the correct value (it’s just
that it can’t show it).
The next step would be to determine the residue of the product, so we divide by 51 (the
modulus) and try to determine the remainder. Again, you will encounter a problem.
After dividing by 51, you’ll still get a really big number (something like “1.326824628 × 1016”).
This time, your calculator might not be able to save the exact number as it has to store too
many decimal values, so our usual method of removing the whole part will not work. In fact,
depending on your calculator, we might not be able to solve the problem using this method.
Do not worry too much if you couldn’t follow that, the important thing is that because the
numbers are too big, the capabilities of calculators become an issue. So, we try to make the
numbers smaller first so that the calculators can manage. Thus, we try the second method of
substituting by the residues before applying the operations.
First, determine the residues of the factors:
978,452,579 ≡ 35 (mod 51)
and
691,582,377 ≡ 39 (mod 51)
***Again, due to calculator limitations, you might need to round the value shown in your
calculator, in order to determine the residue
Note that we may have several operations in a mathematical expression. Thus, in modular
arithmetic, we will also follow PEMDAS for the order of operations.
***WARNING: so far, what I have discussed applies to the three operations of addition,
subtraction, and multiplication. Division and exponentiation will be discussed later.***
Also, note that in a chain of congruencies under the same modulus, it is acceptable to write
the modulus operator at the very end. You do not need to indicate the modulus after each
congruence. For example
50 ≡ 40 ≡ 30 ≡ 20 ≡ 10 ≡ 0 (mod 10)
is preferred over
50 ≡ 40 (mod 10) ≡ 30 (mod 10) ≡ 20 (mod 10) ≡ 10 (mod 10) ≡ 0 (mod 10)
In fact, when changing the modulus or dealing with different moduli, we usually start a new
chain of congruencies for different moduli.
For expressions with more operations, you don’t need to substitute all the numbers with their
residues. Substitution by residues is usually done because the numbers get too big. This means
that in the process of computation, after correctly applying some of the operations using the
original numbers, you may substitute by the residue once you feel the current result is getting
too big.
Lastly, recall earlier that I asked if the modulus is some number n, what would its possible
residues be? The alternative interpretation of the answer is that if the number is NOT
negative, AND is strictly less than the modulus, then the number is a residue. Kindly make use
of that as a quick check to determine if a number is already a residue or not.
Arithmetics: Exponentiation
There are two remaining operations to discuss, division and exponentiation. We will start with
exponentiation.
In modular arithmetic, we CAN NOT easily substitute exponents with other numbers in the
same equivalence class. There are some substitutions that are allowed, but they are not
straight-forward.
Exponentiation by positive integers retains its definition from the usual arithmetic. That is, any
number raised to a positive exponent means the number is multiplied to itself as many times
as the exponent. In other words, for some number n raised to the power of p, this is defined to
be n multiplied to itself p times. Symbolically, we write:
𝑛𝑝 = ⏟
𝑛 × 𝑛 × 𝑛 × ⋯× 𝑛 × 𝑛 × 𝑛
𝑝 times
You should be familiar with this idea from previous math subjects. This is our definition for
when p is positive. When p is zero, then any number raised to the power of zero is equal to
one, EXCEPT zero. We leave zero raised to the power of zero as undefined.
Note that what this actually means is that even though we are using the same numbers, they
have different meanings. The base is a number from the modular system. The exponent is our
usual counting numbers. It turns out there are relationships between the two, but those will
not be discussed in this class.
2) 53 = 5 × 5 × 5 = 125
2) 29 = 2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 = 512
3) 44 = 4 × 4 × 4 × 4 = 256
Recall though that in modular arithmetic, we write our answers as residues.
4) 53 = 125 ≡ 6 (mod 7)
5) 29 = 512 ≡ 2 (mod 6)
AGAIN, do not make the mistake of substituting exponents by congruent values. Remember,
the exponent is a counting number, NOT a number from the modular system, so we can’t
make use of the modular system properties.
You should also note that since the definition is essentially a product, you may substitute the
base by another number in its equivalence class. This applies only to the base! For example, to
determine the residue of 123 mod 7, since the residue of 12 mod 7 is 5, we can substitute 12
by 5 to get
123 ≡ 53 (mod 7)
So, now we solve for the residue of 53 (mod 7), which was done above (number 4), and the
answer would be 6.
This is one scenario where we are using the same numbers, but they have different meanings.
The base is an integer where a modulo is applied. The exponent is a count. In other areas of
math, this happens sometimes, so it is best to understand what each mathematical statement
really means.
Note that by this definition, and since modular multiplication includes the properties of usual
multiplication, some of the properties of the usual definition of exponentiation also carry over.
For now, the important properties that carries over are:
2) When two powers with the same base are multiplied, then this is equivalent to the base
being raised to the power of the sum of the exponents.
Bx × by = b(x+y)
2) A base raised to the power of some exponent, and then that result raised to the power of
another exponent is the same as the same base raised to the power of the product of the two
exponents.
(bx)y = bxy
or
b = (bx)y
xy
The second one makes use of the same idea, but instead of combining the exponents as a
product, you will separate an exponent into one of its possible factor pairs.
That is the basics of exponents in modular arithmetic, but further investigation leads to some
interesting behaviour.
***** The following discussion may be difficult to follow, but do not worry. The *****
***** important part of this section is to see how some of the exponentiation was done *****
First, let’s look at the integers under modulo 3 and see what happens to the residues when
they are raised to some exponents.
Residues
Exponent
0 1 2
1 0 1 2
2 0 1 1
3 0 1 2
4 0 1 1
5 0 1 2
6 0 1 1
7 0 1 2
8 0 1 1
9 0 1 2
10 0 1 1
*The very first column are the exponents. The first row of numbers (to the right of “Exponent”
that are in bold and underlined) are the residues under the given modulo. The entries below
these are the resulting residue when the number in the first row is raised to the power of the
indicated exponent on the corresponding row. For example, the cell under the column for “2”,
and along the row for an exponent of 5, the entry would correspond to the residue of
25 mod 3
which would be
25 = 32 ≡ 2 mod 3
That is, the resulting residue is 2, and so the entry in that cell should be 2.
Note that when computing the number raised to an exponent you may make use of the
property indicated above so that the numbers you are dealing with are smaller. For example,
then
1212
≡ 12(4+4+4)
≡ 124 × 124 × 124
≡ 20,736 × 20,736 × 20,736
≡6×6×6
≡ 216
≡ 6 (mod 15)
Thus, you can say that the residue of 1212 mod 15 is 6. Depending on your calculator, trying to
compute for the residue of 1212 mod 15 directly may result in an error due to calculator
limitations. By separating the exponent into smaller numbers, the calculator will more likely be
able to handle the computation correctly.
Going back to the table, note that from an exponent of 3 onwards, the values repeat
themselves.
You’ll notice that after a certain exponent, the residues start repeating themselves.
Again, after a certain exponent, the residues start repeating themselves. For residues 0 and 1,
the repetition starts after an exponent of 1. For residues 2 and 4, the repetition starts after an
exponent of 3. For residues 3 and 5, the repetition starts after an exponent of 6. Lastly, for
residue 6, the repetition starts after an exponent of 2.
First thing to note, in the above cases, the modulus was a prime number. Second thing to note
is that for the same modulus, some residues start their repetition after different exponents,
but all of them repeat after an exponent of one less than the modulus.
What if the modulus isn’t prime? Let’s take a look at what happens under modulo 9.
Residues
Exponent
0 1 2 3 4 5 6 7 8
1 0 1 2 3 4 5 6 7 8
2 0 1 4 0 7 7 0 4 1
3 0 1 8 0 1 8 0 1 8
4 0 1 7 0 4 4 0 7 1
5 0 1 5 0 7 2 0 4 8
6 0 1 1 0 1 1 0 1 1
7 0 1 2 0 4 5 0 7 8
8 0 1 4 0 7 7 0 4 1
9 0 1 8 0 1 8 0 1 8
10 0 1 7 0 4 4 0 7 1
11 0 1 5 0 7 2 0 4 8
12 0 1 1 0 1 1 0 1 1
You’ll notice that there is still a repetition, but it doesn’t look as nice as for those with prime
numbers. In particular, numbers that are not relatively prime to the modulo never have a 1 in
their pattern. Recall from your previous math classes that if two numbers are relatively prime
if the biggest number that divides both of them is 1. Thus, if there is a number bigger than 1
that divides both the numbers, then those two numbers are NOT relatively prime.
Something else you might have noticed is that for all the tables, the last column follows a
similar pattern. It would be the residue followed by 1, then the residue, then 1 again, and this
pattern repeats itself.
The reason is as follows. In our usual exponents, you should be familiar with the fact that –1
raised to the power of an even exponent is 1, while –1 raised to the power of an odd exponent
will still be –1. That is,
(–1)p is 1 if p is even
and
p
(–1) is –1 if p is odd.
So, with the base always fixed at –1, and starting with an exponent of 1 and increasing it by 1,
you would get the following
(–1)1 = –1, (–1)2 = 1, (–1)3 = –1, (–1)4 = 1, (–1)5 = –1, (–1)6 = 1, (–1)7 = –1, (–1)8 = 1, etc.
Cleaning this up to show only the results, you will see that we get a pattern of alternating –1’s
and 1’s:
–1, 1, –1, 1, –1, 1, –1, 1, –1, 1, etc.
–1 ≡ 0 – 1 ≡ n –1 (mod n)
So, our alternating pattern of –1’s and 1’s as residues would be an alternating pattern of n – 1
and 1:
n – 1, 1, n – 1, 1, n – 1, 1, n – 1, 1, n – 1, 1, etc.
and that is exactly the pattern that we see in the last column.
***** Remember, the most important part of the above section is on how to deal with *****
***** problematic exponents. If you couldn’t quite follow the other parts, that’s fine. *****
*****************************************************************************
The last operation we consider is division. In modular arithmetic, you have to be careful when
dividing as there are cases where, aside from zero, certain divisors are not allowed. This will be
discussed later.
In the usual arithmetic, the division operation can be interpreted as how to equally share a
quantity (the dividend being the quantity to be shared; the divisor being how many shares;
and the resulting quotient being the size of each share). Unfortunately, this interpretation
doesn’t work well with modular arithmetic. Instead, we will use the idea of the multiplicative
inverse.
If you recall, in the usual arithmetic, the multiplicative inverse of a number x is the number y
so that x times y equals one. For example, the multiplicative inverse of 5 is 0.2 because when
you multiply those two numbers, the product is one.
Note that if y is the multiplicative inverse of x, then x is the multiplicative inverse of y. In other
words, if you can find two number a and b so that their product is one, then a and b are said to
be multiplicative inverses of each other (that is, a is a multiplicative inverse of b, and b is a
multiplicative inverse of a).
For example, consider 8 times 8 under modulo 9. You should note that the residue of the
product is 1, that is
8 × 8 ≡ 1 (mod 9)
Another example, consider 5 times 9 under modulo 11. You should note that the residue of
the product is 1, that is
5 × 9 ≡ 1 (mod 11)
Thus, 9 is the multiplicative inverse of 5 under modulo 11, and 5 is the multiplicative inverse of
9 under modulo 11.
**A common question is if “1” is fixed under the definition of multiplicative inverse. The
answer is yes. The product should be congruent to 1 under the corresponding modulo. If you
want to be more technical, the product should be congruent to the multiplicative identity,
which happens to be 1.
One thing to note is that the examples above use residues. Technically, in modular arithmetic,
if a number has a multiplicative inverse, then it has infinitely many multiplicative inverses, but
they are all in the same equivalence class (so we can think of them as being the same). For
example, consider 5 times 130 under modulo 11. Again, you should get that the residue of the
product is 1, that is
5 × 130 ≡ 1 (mod 11)
So, in this case, 130 is also a multiplicative inverse of 5 under modulo 11. So, we’ve found that
both 9 and 130 are multiplicative inverses of 5 under modulo 11. But, you should note that the
residue of 130 under modulo 11 is 9, so 130 is congruent to 9 under modulo 11, that is
In other words, any number that is congruent to 9 (mod 11) will also be a multiplicative
inverse of 5 (mod 11).
TO AVOID CONFUSION, when we refer to “THE” multiplicative inverse, we are referring to THE
residue of any of its multiplicative inverses. Using the above example, 130 is a multiplicative
inverse of 5 under modulo 11 while 9 is the multiplicative inverse of 5 under modulo 11.
Now, there is a certain problem. As mentioned before, not all numbers will have multiplicative
inverses, and this depends on the modulus. The simplest example to test is 2 under modulo 4.
Again, we will just be using residues, so let’s take a note of all of the possible residues under
modulo 4. You should get that all of the possible residues in modulo 4 are 0, 1, 2, and 3. So,
let’s try multiplying 2 to all the residues and see if any of the products are congruent to 1.
Taking the indicated products, we have:
0 × 2 ≡ 0 (mod 4)
1 × 2 ≡ 2 (mod 4)
2 × 2 ≡ 0 (mod 4)
3 × 2 ≡ 2 (mod 4)
Thus, as you can see, no matter what I multiply to 2, in modulo 4, the product will never be 1
(it’s either 0 or 2).
There’s deeper math involved, but just note that if the number and the modulus are not
relatively prime, then the number will not have a multiplicative inverse under that modulo.
So, before you look for the multiplicative inverse, if you know/remember how, you may check
if the greatest common divisor between the number and the modulus is one. If it’s not one,
then the number does not have a multiplicative inverse under that modulo.
BUT! If you don’t know how, don’t worry, the method of finding the multiplicative inverse that
we will go through will let you know.
Before we proceed, there are several ways to determine the multiplicative inverse. One way is
to try multiplying by all possible residues. Unfortunately, if the modulus is large, you will have
to make many computations. Another is to make use of exponentiation. I will not go through
this method here, but if you’d like to see how, you may ask me to show you in our next session
(if you know the right exponent to use, it’s relatively simple. The problem is determining the
right exponent, which is not that difficult, but may be time consuming, depending on the
actual number. Finding the right exponent makes use of what’s known as Euler’s totient
function). The method that will be discussed is a modified representation of what’s known as
the extended Euclidean algorithm.
This example is when the number does not have a multiplicative inverse. Let’s take a look at
24 mod 729.
First write the modulus (in this case 729), followed by a minus sign, followed by the number
we are testing (in this case 24), followed by an open parenthesis and some empty space (to be
filled in later) before closing it, and lastly the equal sign. What you write should look
something like this:
729 – 24( ) =
Second, in the parenthesis, you will write how many 24s go into 729 (that is, the whole part
when you divide 729 by 24). In this case, the parenthesis will be filled with 30, and what you
write should look something like
729 – 24( 30 ) =
Third, on the right side of the equation, write down the result of carrying out the operations
that are on the left side of the equation. In this case, the result is 9, and what you write should
look something like
729 – 24( 30 ) = 9
Great! This is how we form our first equation. To get the next equation, we will ignore the first
number (in this case, 729) as well as the number in the parenthesis (in this case, 30), and use
the remaining numbers, in the order they are shown, to start our next equation (in this case,
24, and 9). We will write it just like the first step, that is, the larger number minus the smaller
number, followed by an empty parenthesis, then an equal sign. So, what you have should
looks something like:
24 – 9( ) =
Again, follow the previous steps to complete the equation. In this case, the parenthesis is filled
out with the whole part when 24 is divided by 9, which would be 2. So, you would have
something that looks like:
24 – 9( 2 ) =
After that, carry out the operations and write the result on the right side of the equality. In this
case, you should get 6, and what you will write should look something like:
24 – 9( 2 ) = 6
Now that the next equation is complete, we will make another equation. Just like before,
ignore the first number as well as the number in the parenthesis, and use the remaining
numbers. In this case, we have the numbers 9, and 6.
Again, setting it up like we did before, what you write should look something like:
9 – 6( ) =
Following the procedure, we will in the parenthesis with the whole part when you divide 9 by
6. In this case, it will be 1, and what you write should look something like:
9 – 6( 1 ) =
To complete the equation, we carry out the operations and write the result on the right side of
the equality. In this case it should be 3. Your completed equation should look like:
9 – 6( 1 ) = 3
We will make one final equation in the same way. That is, ignore the first number as well as
the number in the parenthesis, and use the remaining numbers. In this case, we are left with a
6, and a 3.
So, just like before, what you write should look something like:
6 – 3( ) =
Following the procedure, you fill out the parenthesis with the whole part when you divide 6 by
3, which would be 2 in this case. So, what you write should look something like:
6 – 3( 2 ) =
Then complete the equation by carrying out the operations and writing the result on the right
side of the equality, which would be 0 in this case. So, your equation should look something
like:
6 – 3( 2 ) = 0.
That’s it. We stop once we have a zero on the right side (partly because if we continued, you
should notice that the next equation would require dividing 3 by 0, which would be
undefined).
Okay, first, let’s take a look at the last equation, in this case it’s
6 – 3( 2 ) = 0.
The number next to the parenthesis is the greatest common divisor between our two
original numbers. So, in this case, 3 is the number next to the parenthesis, and our original
numbers are 24 and 729. Thus, 3 is the greatest common divisor between 24 and 729, which
means that they are not relatively prime. Hence, 24 does not have a multiplicative inverse
under modulo 729. You may also verify that 4 does indeed divide both 24 and 729, and the
results of these divisions would be 8 and 243, respectively.
Okay, so, to review the process, you set up the first equation using the modulus, and the
number whose multiplicative inverse you are looking for. Once your first equation is done, you
make the next equation using numbers from the previous equation. You keep doing this until
your equation has a zero on the right side of the equality.
Once you have the last equation, you look at the number next to the parenthesis. If it’s not a
1, then your original number does not have a multiplicative inverse under that modulo. If it is a
1, then there is a multiplicative inverse, and we will look at how to deal with that in the next
example.
In this example, the number has a multiplicative inverse. Let’s take a look at 31 mod 729.
I will not go through the steps again, but following the procedure above, you should get the
following equations:
729 – 31( 23 ) = 16
31 – 16( 1 ) = 15
16 – 15( 1 ) = 1
15 – 1( 15 ) = 0
Again, we stopped the process because our last equation ends with a zero. If we look at the
number next to the parenthesis, it’s a 1. This means that the greatest common divisor of 31
and 729 is 1, so 31 and 729 are relatively prime, which means that 31 must have a
multiplicative inverse under modulo 729.
Great, we know there must be a multiplicative inverse, but how do we get it? Technically,
there are various ways you can do this, some less systematic than what I will show, but
possibly faster.
The idea is that through substitutions, we want to end up with an equation that looks
something like
729( x ) + 31( y ) = 1
for our example. That is, the modulus times some integer x, plus the number whose inverse
we are looking for times another integer y, and this will equal 1 (again, one is fixed). It will turn
out that y is a multiplicative inverse (you might need to get its residue so that you have the
multiplicative inverse)
To do this, we will make use of the equations that we formed previously (the equations
formed to determine the greatest common divisor). The idea is we will make use of 3
properties that emerge from that process. The first one is that the very first equation has two
of the numbers that we need (the modulus and the number whose inverse we are looking for).
The second property is that if the number does have an inverse, then the second to last
equation formed should always equal one. The third is that these equations are related (the
next equation is formed using two numbers from the previous equation).
So, starting with the second to last equation (that’s equal to 1), we will use the previous
equations to link it back to the first equation (that has the two number that we want, the
modulus and divisor). This linking back is usually called “back substitution”, and it is a bit tricky
because we don’t want to oversimplify. We want to preserve some of the linking numbers. To
see how this works, let’s continue with our example.
First, start with the equation right before the last one, in this case, it would be
16 – 15( 1 ) = 1
Let’s call this equation A.
Next, take a look at the equation before this one, that is:
31 – 16( 1 ) = 15
Let’s call this equation B.
You’ll notice that equation A has a 15, and equation B is equal to 15. We will substitute the left
side of equation B into wherever we see a 15 in equation A. Doing so, you will end up with
something that looks like
16 – [31 – 16( 1 )]( 1 ) = 1
Now, let’s “simplify”. BE CAREFUL! We are NOT simplifying everything outright. Do not
simplify numbers that are not in parentheses. We can only substitute them by other
expressions, but we don’t “combine” them with other numbers. So, the above equation is
simplified as follows
16 – [31 – 16( 1 )]( 1 ) = 1
The ( 1 ) that’s outside the square brace is in parenthesis, so we can distribute it, which results
in:
16 – [31( 1 ) – 16( 1 )( 1 )] = 1
Again, ( 1 )( 1 ) are in parentheses, so we can multiply them together, and the result is that
( 1 )( 1 ) = ( 1 )
Just note that I’ve kept it in parenthesis to remind me that I can combine this number. The
result is:
16 – [31( 1 ) – 16( 1 )] = 1
Next, we remove the square brackets by distributing the minus sign. This results in:
16 – 31( 1 ) + 16( 1 ) = 1
Note that there are two sixteens that are added together, but since we can’t actually add
them, we simplify it by showing that 16 is multiplied by two. This results in:
– 31( 1 ) + 16( 2 ) = 1
Great, we’re almost there. We have the “31” part and the “= 1” part from 729( x ) + 31( y ) = 1.
We just need the 729 part. You’ll notice that we have a 16 in this equation. We can substitute
our first equation ( 729 – 31( 23 ) = 16 ) into this. This will result in
– 31( 1 ) + [729 – 31( 23 )]( 2 ) = 1
Again, we simplify by distributing the ( 2 ) into the square braces, which results in:
– 31( 1 ) + [729( 2 ) – 31( 23 )( 2 )] = 1
Then, we multiply the adjacent parentheses ( 23 )( 2 ), which gives us a 46. The resulting
equation should look like:
– 31( 1 ) + [729( 2 ) – 31( 46 )] = 1
Since the operation before the opening of the square brace is a “+”, we can simply remove the
square brace, which results in
– 31( 1 ) + 729( 2 ) – 31( 46 ) = 1
Then, similar to before, the – 31( 1 ) and – 31( 46 ) combine to form – 31( 47 ). This results in:
729( 2 ) – 31( 47 ) = 1
We’re almost there! You’ll notice that in the form that we want it to look like
729( x ) + 31( y ) = 1
The operation is a “+”, but we have a “–” in our equation. So, we convert the minus into a plus
by making the 47 a negative. This results in:
729( 2 ) + 31( – 47 ) = 1
Great! We have the form that we’re looking for. Look at the number whose multiplicative
inverse we’re looking for, and check the number next to it that’s in parenthesis. That is, we
look at 31 and note that the number next to it in parenthesis is –47. Since –47 is NOT a residue
in modulo 729, that means that –47 is a multiplicative inverse of 31 in modulo 729. In this
case, we want the multiplicative inverse, so we have to find the residue of –47 (mod 729). You
should get that the residue is 682.
You may verify by getting the residue of 31 × 682 (mod 729). The result should be congruent to
1.
Again, I will not go through the details, but we follow with getting the equations (remember,
this process also tells us if the number has a multiplicative inverse or not).
The equations you get are:
1,089 – 35( 31 ) = 4
35 – 4( 8 ) = 3
4 – 3( 1 ) = 1
3 – 1( 3 ) = 0
Checking the last equation, the number next to the parenthesis is a 1, so 35 has a
multiplicative inverse under modulo 1,089.
Cleaning up without changing number that are not in parenthesis, you should get:
–35 + 4( 9 ) = 1
Cleaning up without changing number that are not in parenthesis, you should get:
1,089( 9 ) – 35( 280 ) = 1
Then, convert the minus to a plus by making the number in the parenthesis (to the right of the
minus sign) negative, should result in:
1,089( 9 ) + 35( –280 ) = 1
Last, get the residue of the number in parenthesis (the parenthesis next to the number whose
multiplicative inverse you’re looking for). In this case, we are looking for the residue of:
–280 mod 1,089
Note: In the examples, the last step before getting the residue required you to convert the
minus to a plus. This will not always be the case. If the equation already has a plus, then you
can go ahead and look at the number in the parenthesis and get its residue if necessary.
The examples above formed several equations so that you can see the pattern for the
procedure. Depending on the numbers, sometimes you will have less equations, sometimes
more.
Consider 5 mod 11. As discussed in the first page, its multiplicative inverse is 9. Let’s solve it
using the process. The first step will yield:
11 – 5( ) =
Continuing the process, the next equation you get will be:
5 – 1( 5 ) = 0
Again, we stop since it’s equal to zero. The number next to the parenthesis is a 1, so there is a
multiplicative inverse. Thus, we start with the equation before the last one, which is
11 – 5( 2 ) = 1
Clearly, this is also our first equation, so there will be no back-substitution. This is not a
problem, because what this means is that this equation is almost in the form that we want. In
this case, just note that 11 can be written as 11( 1 ), so our equation will look like:
11( 1 ) – 5( 2 ) = 1
This now looks like what we want: the modulus times some integer plus the number whose
multiplicative inverse we’re looking for times some integer equals one.
So, a multiplicative inverse of 5 is –2 under modulo 11. Getting the residue of –2 mod 11
results in 9. That is,
–2 ≡ 9 mod 11
One more example. This one will be longer, to give you a better idea of the back-substitution
part. I will also put less explanations, so it will look more similar to what your solution would
look like.
423 – 326(1) = 97
326 – 97(3) = 35
97 – 35(2) = 27
35 – 27(1) = 8
27 – 8(3) = 3
8 – 3(2) = 2
3 – 2(1) = 1
2 – 1(2) = 0
Part 2: Back-substitution
3 – 2(1) = 1
Using: 8 – 3(2) = 2
3 – [8 – 3(2)](1) = 1
3 – 8(1) + 3(2)(1) = 1
3(3) – 8(1) = 1
Using: 27 – 8(3) = 3
27(3) – 8(10) = 1
Using: 35 – 27(1) = 8
27(13) – 35(10) = 1
Using: 97 – 35(2) = 27
97(13) – 35(36) = 1
97(121) – 326(36) = 1
423(121) – 326(157) = 1
423(435) – 1,172(157) = 1
3,939(435) – 1,172(1,462) = 1
Now, if the algebra involved seems daunting, there is an alternative. Some of you might have
noticed a pattern in the process. This presentation tries to simplify the algebra by looking at
only the important parts.
For those interested, and I might have mentioned this in the corresponding notes, the process
is actually known as the Euclidean algorithm or Euclid’s algorithm, but I have presented it a bit
differently (in case you search for it online). The process I did above is a slight modification to
the usual Euclidean algorithm. So, this alternative is still based on the algorithm, but ignores
certain parts.
113 – 40(2) = 33
40 – 33(1) = 7
33 – 7(4) = 5
7 – 5(1) = 2
5 – 2(2) = 1
2 – 1(2) = 0.
*WARNING* Remember, at the last equation, if the number next to the parenthesis is NOT
one, then there is no multiplicative inverse. So there will be no point in proceeding. Thankfully,
in this example, it is indeed a one, so we can proceed.
Next, make a table with 2 columns, and fill the first column with the numbers in parenthesis,
BUT, make them negative, AND don’t include the last equation.
Note that I will include an additional column for the equations to help you follow the process,
but when you do it, you don’t have to include this additional column (you may still do so if you
want, in order to keep track of the equations). You also don’t need to put the headings for the
columns.
Negative of number in
Equations
parenthesis
113 – 40(2) = 33 –2
40 – 33(1) = 7 –1
33 – 7(4) = 5 –4
7 – 5(1) = 2 –1
5 – 2(2) = 1 –2
Then, at the bottom of the next column, copy the number that is on its left, and write a “1”
below it. The resulting table is:
Negative of number in
Equations
parenthesis
113 – 40(2) = 33 –2
40 – 33(1) = 7 –1
33 – 7(4) = 5 –4
7 – 5(1) = 2 –1
5 – 2(2) = 1 –2 –2
1
To emphasize, at the bottom of the last column, you write a “1”, this is always fixed at “1”, no
matter what is given.
We will now fill up the table sequentially, from the last empty cell, going up.
On the bottom most cell that is empty, multiply the number to its left with the number below
it. To this product, you will add the number two rows below it. This is the value that you will
put in the cell.
Negative of number in
Equations
parenthesis
113 – 40(2) = 33 –2
40 – 33(1) = 7 –1
33 – 7(4) = 5 –4
7 – 5(1) = 2 –1 3
5 – 2(2) = 1 –2 –2
1
Where 3 is the result of multiplying –1 (the number to its left) and –2 (the number below it),
and then adding 1 (the number two rows below it). That is:
3 = –1 × –2 + 1
We follow this pattern to fill up the table. So, the next empty cell above will be filled with the
result of multiplying the number to its left with the number below it, and then adding the
number two rows below it.
Negative of number in
Equations
parenthesis
113 – 40(2) = 33 –2
40 – 33(1) = 7 –1
33 – 7(4) = 5 –4 –14
7 – 5(1) = 2 –1 3
5 – 2(2) = 1 –2 –2
1
Again, for the cell in light blue, the number to its left is –4, the number below it is 3, and the
number two rows below it is –2. So, –14 is the result of multiplying –4 with 3 and then adding
–2 to the result. That is:
–14 = –4 × 3 + –2
Try to fill out the rest of the table. The completed table will look like:
Negative of number in
Equations
parenthesis
113 – 40(2) = 33 –2 –48
40 – 33(1) = 7 –1 17
33 – 7(4) = 5 –4 –14
7 – 5(1) = 2 –1 3
5 – 2(2) = 1 –2 –2
1
The inverse will be the RESIDUE of the top number in the last column. Emphasis that you may
still need to determine the residue if it is not already a residue.
For this example, you will need to get the residue of –48 mod 113. Doing so gives us that the
multiplicative inverse of 40 mod 113 is 65.
To highlight an unusual case, we will use this method with another example. This is basically
the case when no back-substitution is used since there are only two equations.
5 – 2(2) = 1
2 – 1(2) = 0
*REMINDER* Before continuing with the next part, don’t forget to check if there is a
multiplicative inverse or not.
Next, we make the table I will not go through the step-by-step process, but, I will include an
additional column for the equations to help you follow the process. Again though, when you
do it, you don’t have to include this additional column. You also don’t need to put the
headings for the columns.
You should notice that after setting things up, there are no empty squares to fill. In this case,
the same rule applies. The RESIDUE of the top number in the last column is the inverse.
*NOTE* This will tie into a later topic, which is linear congruences. For linear congruences, in
the last equation, the number next to the parenthesis is not always a one. That’s okay, you can
still follow this process. Remember, this is just a different way of PRESENTING the process, but
it is essentially the same process as discussed in the notes.
To add an additional example, and so you can compare processes (the back substitution part in
particular), I will solve the last example in the previous method, but using this method this
time.
**Reminders**
1. Stop when the equation equals zero.
2. Check to make sure that in the last equation, the number next to the parenthesis is a 1. If
it’s not, then there is no multiplicative inverse and you can stop.
Step 2 – In the first column, write out the negative of the numbers in parenthesis in the
equations. Place them in the same order as the equations.
3,939 – 1,172(3) = 423 –3
1,172 – 423(2) = 326 –2
423 – 326(1) = 97 –1
326 – 97(3) = 35 –3
97 – 35(2) = 27 –2
35 – 27(1) = 8 –1
27 – 8(3) = 3 –3
8 – 3(2) = 2 –2
3 – 2(1) = 1 –1
Step 4 – Look at the bottom of the first column. Copy this number to the cell next to it.
3,939 – 1,172(3) = 423 –3
1,172 – 423(2) = 326 –2
423 – 326(1) = 97 –1
326 – 97(3) = 35 –3
97 – 35(2) = 27 –2
35 – 27(1) = 8 –1
27 – 8(3) = 3 –3
8 – 3(2) = 2 –2
3 – 2(1) = 1 –1 –1
2 – 1(2) = 0 1
Part 4: Get the residue of the uppermost number in the second column, if it is not already a
residue. That is the multiplicative inverse
– 1,462 ≡ 2,477 (mod 3,939)
Answer: 2,477
b-1 mod n
refers to the multiplicative inverse of b in modulo n. Note that this is really for notation
purposes. Sometimes, we just want to note that the value being used is the multiplicative
inverse of a particular number without actually computing for it.
For example,
5-1 mod 7
refers to the multiplicative inverse of 5 in modulo 7. The actual value for it is 3 in modulo 7. So,
whenever you see 5-1, you can substitute it with a 3 in modulo 7. Remember though, you may
substitute by congruent numbers, so technically, you can substitute by any of its multiplicative
inverses. But, for simplicity, we will just substitute by THE multiplicative inverse for now (and
do further substitutions later, if needed). Essentially, you have that
5-1 ≡ 3 mod 7
a ÷ b ≡ a × b-1 mod n
As you can see, dividing by b is the same as multiplying by b-1 (the multiplicative inverse of b).
Substitute by the actual multiplicative inverse. In this case, 3 is the inverse of 5 in modulo 7.
4 × 5-1 ≡ 4 × 3 mod 7
Note that I did not show the process of determining the multiplicative inverse of 5 in modulo
7. That process is basically what was discussed in Part 1 (Multiplicative Inverse).
Solution (presented differently, in a more compact form, from the previous example):
Again, to determine that 35-1 ≡ 27 mod 59 (the inverse of 35 in modulo 59 is 27), you would
have to go through the process described in Part 1.
Please note, division is only defined if the multiplicative inverse exists, otherwise, the
expression is undefined.
For example,
5 ÷ 7 mod 28
Linear Congruences
We will now learn to solve linear congruences of the form ax ≡ b mod n, where a, and b are
integers, n is a positive number, and x is the variable that we are trying to solve for.
1) 12x ≡ 13 mod 20
2) 6x ≡ 15 mod 27
3) 8x ≡ 12 mod 19
Note that there are other ways to solve these types of equations. Some may seem easier, but
they are not systematic, so they require a certain degree of guessing and familiarity with
numbers. I will assume that a significant number of you are not comfortable enough with
numbers and algebra to be able to use these methods. I will not require you to use any
particular method, but if you want to see if you’re comfortable enough with your math skills,
you may check this video: https://youtu.be/Q619hYCOhZ4. It is about 15 minutes long, and
about 4 problems are solved. The video is a bit older, and there are many other videos. The
video is short, so it only highlights critical ideas for solving in less systematic ways. If you’d like
more details, you can ask me, or you can look for longer videos. If you feel that you almost get
the idea behind these methods but have questions, feel free to ask me about it. With that
being said, I will now proceed to explain the systematic method.
Recall, the following steps are for linear equations that are in the following forms:
ax ≡ b mod n
If the congruence is not in that form, see if you can apply some of the modular arithmetics to
convert it to that form.
Step 1.1: Determine the greatest common divisor of a and n. We will refer to this value as d.
Remember, a is the number multiplied to x, and n is the modulus.
Also, if you remember how to solve for the greatest common divisor, you may use the method
that you’re comfortable with. You may also use the first part of the method for finding the
multiplicative inverse that was described in Modular Arithmetic 05. The first part referring to
the forming of the equations. If you look at the first example in the notes of Modular
Arithmetic 5 (the one with no multiplicative inverse), it tells you where the greatest common
divisor can be found. I will use this method for the solved examples, because (as you will see
later), the rest of the process for finding the multiplicative inverse will be used if there is a
solution.
Step 1.2: Check if d divides b. Recall that d is the greatest common divisor from step 1.
Case 1: If d does not divide b, then there is NO SOLUTION.
Case 2: If d does divide b, then there are solutions, and there will be d distinct
solutions (meaning that the value of d also tells us how many distinct
solutions there will be).
Note that if you have no solutions, then you are done. So, the following steps are for when you
do have solutions.
Part 2 – Determining ONE particular solution. Remember, do not proceed to this part unless
you have Case 2 from Step 1.2. That is, there will be at least one solution.
Step 2.1: Assuming there is at least one solution, then you will use the same method that was
used for finding THE multiplicative inverse. We will refer to this value as Y.
To clarify, even if the greatest common divisor is NOT one (meaning that there is no
multiplicative inverse), you will continue with the back substitution (or table) process, as if
there is an inverse. The residue of the “inverse” that results from this process will be referred
to as Y.
Step 2.3: Get the residue of Y × Z mod n. We will refer to this value as x1.
x1 is in fact one of the solutions.
Note that if there is only one solution, then you can stop at Step 2.3. x1 is the answer. The next
steps are for when there are more than one solution. That is, if there are solutions and d is
strictly greater than one.
Part 3 – Getting the other solutions. Remember, do not proceed to this part unless you have
solved for x1 in Step 2.3 AND the value of d (computed in Step 1.1) is strictly greater than 1.
Step 3.2.a: Check the value of x1 – k. If it is a residue, note this value down as it is also a
solution. Using this new value, subtract k again and check if the resulting value is a residue. If it
is, again, note the value down as another solution. Continue subtracting k from the new values
until the resulting value is not a residue. Once the result is not a residue, you will stop. Do NOT
note down the value that is NOT a residue.
To be clear, you are checking if the values are residues in modulo n. Also, as a reminder, if the
modulus is n, then the residues are 0, 1, 2, …, n – 1 (that is, the residues are from zero up to
one less than the modulus). If you keep this in mind, you don’t have to do the computational
process of determining residues.
Step 3.2.b: Check the value of x1 + k. If it is a residue, note this value down as it is also a
solution. Using this new value, add k again and check if the resulting value is a residue. If it is,
again, note the value down as another solution. Continue adding k to the new values until the
resulting value is not a residue. Once the result is not a residue, you will stop. Do NOT note
down the value that is NOT a residue.
Repeating this for emphasis: to be clear, you are checking if the values are residues in modulo
n. Also, as a reminder, if the modulus is n, then the residues are 0, 1, 2, …, n – 1 (that is, the
residues are from zero up to one less than the modulus). If you keep this in mind, you don’t
have to do the computational process.
Step 3.3: The solutions are x1 and all the values you listed in Step 3.2.a AND Step 3.2.b. It is
implied that the values are all under modulo n.
Note that Step 3.2.a and Step 3.2.b are interchangeable. You may do Step 3.2.a first followed
by Step 3.2.b OR Step 3.2.b first followed by Step 3.2.a.
The process has ended since you have found all the solutions. There are no more steps or
parts.
Remember, we first form the equations until we have an equation that equals zero.
20 – 12(1) = 8
12 – 8 (1) = 4
8 – 4(2) = 0
In the equation that equals zero (the last one), the number next to the parenthesis is the
greatest common divisor. In this case, it is 4.
Example 2: 6x ≡ 15 mod 27
27 – 6(4) = 3
6 – 3(2) = 0
This is case 2, so there are solutions. In fact, there will be 3 solutions since the greatest
common divisor is 3.
Since there are solutions, proceed to Part 2 to find one particular solution.
27 – 6(4) = 3
27 + 6(–4) = 3.
The residue is 7.
Remember, there are 3 solutions (3 coming from the greatest common divisor of 6 and 27).
We also have one particular solution. Thus, we proceed with Part 3.
Step 3.1: 27 ÷ 3 = 9.
Remember, this is from n ÷ d.
Step 3.2.a: 7 – 9 = –2. This is not a residue, so we stop, and do NOT note anything down.
**Remember, the residues for a modulus of 27 are 0, 1, 2, …, 23, 24, 25, and 26.
Step 3.2.b:
7 + 9 = 16. This is a residue. Note this down and add 9 to it again.
16 + 9 = 25. Again, this is a residue, so we note it down, then add 9 to it again.
25 + 9 = 34. This is not a reside, so we stop, and do NOT note down this value.
Step 3.3: The solutions are 7, 16, and 25 all in modulo 27.
Example 3: 8x ≡ 12 mod 19
19 – 8(2) = 3
8 – 3(2) = 2
3 – 2(1) = 1
2 – 1(2) = 0
The greatest common divisor is 1.
*This means that if there is a solution, there will only be 1.
3 – 2(1) = 1
3 – [8 – 3(2)](1) = 1
8(–1) + 3(3) = 1
19(3) + 8(–7) = 1
12 × 12 = 144 ≡ 11 mod 19
We do NOT proceed with Part 3, since the greatest common divisor from Step 1.1 is equal to 1.
Note that when you solve these on your own, you do not need to present your solution the
same way as above. In particular, you don’t need to include the explanations. As mentioned
before, there are other ways of solving these that seem faster, but they are less systematic.
You may use other methods if you are more comfortable with them.
Also, note that the numbers used in the examples are already residues. If you encounter a
problem where the values used are not residues, if they are very large, it is recommended to
substitute by residues first, before trying to solve them.
For example, 176x ≡ 4,521 mod 87 would become 2x ≡ 84 mod 87 because the residue of 176
mod 87 is 2 and the residue of 4,521 mod 87 is 84. If you want to solve for x, feel free to try.
You should get only one answer, and it should be 42.
************************************************************
******************** END OF NOTES ********************
************************************************************