One of the most basic and useful notions in number theory is modular arithmetic, or congruences.
Let be integers with We say that
(read: is congruent to mod ) if is a multiple (positive or negative or zero) of
Another formulation is that if and differ by a multiple of This can be rewritten as for some integer (positive or negative).
Note: Many computer programs regard as equal to the number 7, namely, the remainder obtained when 17 is divided by 10 (often written as ). The notion of congruence we use is closely related. We have that two numbers are congruent mod if they yield the same remainders when divided by For example, because and are equal.
Congruence behaves very much like equality. In fact, the notation for congruence was intentionally chosen to resemble the notation for equality.
Let be integers with
if and only if
if and only if
If and then
Proof. In (1), means that is a multiple of which is the same as In (2), we have so In (3), if write Then so Reversing the roles of and gives the reverse implication. For (4), write and Then so
Usually, we have and we work with the integers mod denoted These may be regarded as the set with addition, subtraction, and multiplication mod If is any integer, we may divide by and obtain a remainder in this set:
(This is just division with remainder; is the quotient and is the remainder.) Then so every number is congruent mod to some integer with
Let be integers with and suppose and Then
Proof. Write and for integers and Then so The proof that is similar. For multiplication, we have so
The proposition says you can perform the usual arithmetic operations of addition, subtraction, and multiplication with congruences. You must be careful, however, when trying to perform division, as we’ll see.
If we take two numbers and want to multiply them modulo we start by multiplying them as integers. If the product is less than we stop. If the product is larger than we divide by and take the remainder. Addition and subtraction are done similarly. For example, the integers modulo have the following addition table:
A table for multiplication mod 6 is
Here is an example of how we can do algebra mod Consider the following problem: Solve
SOLUTION
There is nothing wrong with negative answers, but usually we write the final answer as an integer from 0 to when we are working mod
Division is much trickier mod than it is with rational numbers. The general rule is that you can divide by when
Let be integers with and with If then In other words, if and are relatively prime, we can divide both sides of the congruence by
Proof Since there exist integers such that Multiply by to obtain
Since is a multiple of by assumption, and is also a multiple of we find that is a multiple of This means that
Solve:
SOLUTION
The division by 2 is allowed since
Solve:
SOLUTION
Now what do we do? We want to divide by 5, but what does 7/5 mean mod 11? Note that So is the same as Now we can divide by 5 and obtain as the answer. Note that so 8 acts like 7/5.
The last example can be done another way. Since we see that 9 is the multiplicative inverse of Therefore, dividing by 5 can be accomplished by multiplying by 9. If we want to solve we multiply both sides by 9 and obtain
Suppose Let and be integers such that (they can be found using the extended Euclidean algorithm). Then so is the multiplicative inverse for
Proof. Since we see that is a multiple of
Notation: We let denote this so satisfies
The extended Euclidean algorithm is fairly efficient for computing the multiplicative inverse of by the method stated in the proposition.
Solve
SOLUTION
In Section 3.2, from the calculation of we obtained
This says that
Multiplying both sides of the original congruence by 2471 yields
In practice, this means that if we are working mod 12345 and we encounter the fraction 4/11111, we can replace it with 9884. This might seem a little strange, but think about what 4/11111 means. It’s simply a symbol to represent a quantity that, when multiplied by 11111, yields 4. When we are working mod 12345, the number 9884 also has this property since
Let’s summarize some of the discussion:
Use the extended Euclidean algorithm to find integers and such that
when
(Equivalently, you could be working mod and encounter a fraction with )
Use the extended Euclidean algorithm to find integers and such that
The solution is (equivalently, replace the fraction with ).
Occasionally we will need to solve congruences of the form when The procedure is as follows:
If does not divide there is no solution.
Assume Consider the new congruence
Note that are integers and Solve this congruence by the above procedure to obtain a solution
The solutions of the original congruence are
Solve
SOLUTION
which divides 21. Divide by 3 to obtain the new congruence A solution can be obtained by trying a few numbers, or by using the extended Euclidean algorithm. The solutions to the original congruence are
The preceding congruences contained to the first power. However, nonlinear congruences are also useful. In several places in this book, we will meet equations of the form
First, consider The solutions are as we can see by trying the values for In general, when is an odd prime, has exactly the two solutions (see Exercise 15).
Now consider If we try the numbers for we find that are solutions. For example, Therefore, a quadratic congruence for a composite modulus can have more than two solutions, in contrast to the fact that a quadratic equation with real numbers, for example, can have at most two solutions. In Section 3.4, we’ll discuss this phenomenon. In Chapters 9 (factoring), 18 (flipping coins), and 19 (identification schemes), we’ll meet applications of this fact.
In many situations, it will be convenient to work with fractions mod For example, is easier to write than (note that ). The general rule is that a fraction can be used mod if Of course, it should be remembered that really means where denotes the integer mod that satisfies But nothing will go wrong if it is treated as a fraction.
Another way to look at this is the following. The symbol “1/2” is simply a symbol with exactly one property: If you multiply 1/2 by 2, you get 1. In all calculations involving the symbol 1/2, this is the only property that is used. When we are working mod 12345, the number 6173 also has this property, since Therefore, and may be used interchangeably.
Why can’t we use fractions with arbitrary denominators? Of course, we cannot use since that would mean dividing by But even if we try to work with we run into trouble. For example, but we cannot multiply both sides by 1/2, since The problem is that Since 2 is a factor of 6, we can think of dividing by 2 as “partially dividing by 0.” In any case, it is not allowed.