22.5 KB · commit a9602da
Solving linear congruences, which have the form ax≡b(modm), is an essential task in the study of number theory and its applications, just as solving linear equations plays an important role in calculus and linear algebra. To solve linear congruences, we employ inverses modulo m. We explain how to work backwards through the steps of the Euclidean algorithm to find inverses modulo m. Once we have found an inverse of a modulo m, we solve the congruence ax≡b(modm) by multiplying both sides of the congruence by this inverse.
Simultaneous systems of linear congruences have been studied since ancient times. For example, the Chinese mathematician Sun-Tsu studied them in the first century. We will show how to solve systems of linear congruences modulo pairwise relatively prime moduli. The result we will prove is called the Chinese remainder theorem, and our proof will give a method to find all solutions of such systems of congruences. We will also show how to use the Chinese remainder theorem as a basis for performing arithmetic with large integers.
We will introduce a useful result of Fermat, known as Fermat's little theorem, which states that if p is prime and p does not divide a, then ap−1≡1(modp). We will examine the converse of this statement, which will lead us to the concept of a pseudoprime. A pseudoprime m to the base a is a composite integer m that masquerades as a prime by satisfying the congruence am−1≡1(modm). We will also give an example of a Carmichael number, which is a composite integer that is a pseudoprime to all bases a relatively prime to it.
We also introduce the notion of discrete logarithms, which are analogous to ordinary logarithms. To define discrete logarithms we must first define primitive roots. A primitive root of a prime p is an integer r such that every integer not divisible by p is congruent to a power of r modulo p. If r is a primitive root of p and re≡a(modp), then e is the discrete logarithm of a modulo p to the base r. Finding discrete logarithms turns out to be an extremely difficult problem in general. The difficulty of this problem is the basis for the security of many cryptographic systems.
A congruence of the form ax≡b(modm), where m is a positive integer, a and b are integers, and x is a variable, is called a linear congruence. Such congruences arise throughout number theory and its applications.
How can we solve the linear congruence ax≡b(modm), that is, how can we find all integers x that satisfy this congruence? One method that we will describe uses an integer a such that aa≡1(modm), if such an integer exists. Such an integer a is said to be an inverse of a modulo m. Theorem 1 guarantees that an inverse of a modulo m exists whenever a and m are relatively prime.
Proof: By Theorem 6 of Section 4.3, because gcd(a,m)=1, there are integers s and t such that sa+tm=1. This implies that sa+tm≡1(modm). Because tm≡0(modm), it follows that sa≡1(modm). Consequently, s is an inverse of a modulo m. That this inverse is unique modulo m is left as Exercise 7. ■
Using inspection to find an inverse of a modulo m is easy when m is small. To find this inverse, we look for a multiple of a that exceeds a multiple of m by 1. For example, to find an inverse of 3 modulo 7, we can find j⋅3 for j=1,2,…,6, stopping when we find a multiple of 3 that is one more than a multiple of 7. We can speed this approach up if we note that 2⋅3≡−1(mod7). This means that (−2)⋅3≡1(mod7). Hence, 5⋅3≡1(mod7), so 5 is an inverse of 3 modulo 7.
We can design a more efficient algorithm than brute force to find an inverse of a modulo m when gcd(a,m)=1 using the steps of the Euclidean algorithm. By reversing these steps as in Example 17 of Section 4.3, we can find a linear combination sa+tm=1 where s and t are integers. Reducing both sides of this equation modulo m tells us that s is an inverse of a modulo m. We illustrate this procedure in Example 1.
Find an inverse of 3 modulo 7 by first finding Bézout coefficients of 3 and 7. (Note that we have already shown that 5 is an inverse of 3 modulo 7 by inspection.)
Solution: Because gcd(3,7)=1, Theorem 1 tells us that an inverse of 3 modulo 7 exists. The Euclidean algorithm ends quickly when used to find the greatest common divisor of 3 and 7: 7=2⋅3+1. From this equation we see that −2⋅3+1⋅7=1. This shows that −2 and 1 are Bézout coefficients of 3 and 7. We see that −2 is an inverse of 3 modulo 7. Note that every integer congruent to −2 modulo 7 is also an inverse of 3, such as 5,−9,12, and so on. ◀
Find an inverse of 101 modulo 4620.
Solution: First, we use the Euclidean algorithm to show that gcd(101,4620)=1. Then we will reverse the steps to find Bézout coefficients a and b such that 101a+4620b=1. It will then follow that a is an inverse of 101 modulo 4620. The steps used by the Euclidean algorithm to find gcd(101,4620) are:
462010175262332=45⋅101+75=1⋅75+26=2⋅26+23=1⋅23+3=7⋅3+2=1⋅2+1=2⋅1.Because the last nonzero remainder is 1, we know that gcd(101,4620)=1. We can now find the Bézout coefficients for 101 and 4620 by working backwards through these steps:
1=3−1⋅2=3−1⋅(23−7⋅3)=−1⋅23+8⋅3=−1⋅23+8⋅(26−1⋅23)=8⋅26−9⋅23=8⋅26−9⋅(75−2⋅26)=−9⋅75+26⋅26=−9⋅75+26⋅(101−1⋅75)=26⋅101−35⋅75=26⋅101−35⋅(4620−45⋅101)=−35⋅4620+1601⋅101.That −35⋅4620+1601⋅101=1 tells us that −35 and 1601 are Bézout coefficients of 4620 and 101, and 1601 is an inverse of 101 modulo 4620. ◀
Once we have an inverse a of a modulo m, we can solve the congruence ax≡b(modm) by multiplying both sides of the linear congruence by a, as Example 3 illustrates.
What are the solutions of the linear congruence 3x≡4(mod7)?
Solution: By Example 1 we know that −2 is an inverse of 3 modulo 7. Multiplying both sides of the congruence by −2 shows that −2⋅3x≡−2⋅4(mod7). Because −6≡1(mod7) and −8≡6(mod7), it follows that if x is a solution, then x≡−8≡6(mod7).
We need to determine whether every x with x≡6(mod7) is a solution. Assume that x≡6(mod7). Then, by Theorem 5 of Section 4.1, it follows that 3x≡3⋅6=18≡4(mod7), which shows that all such x satisfy the congruence. We conclude that the solutions to the congruence are the integers x such that x≡6(mod7), namely, 6,13,20,… and −1,−8,−15,…. ◀
Systems of linear congruences arise in many contexts. For example, as we will see later, they are the basis for a method that can be used to perform arithmetic with large integers.
In the first century, the Chinese mathematician Sun-Tsu asked:
There are certain things whose number is unknown. When divided by 3, the remainder is 2; when divided by 5, the remainder is 3; and when divided by 7, the remainder is 2. What will be the number of things?
This puzzle can be translated into the following question: What are the solutions of the system of congruences
xxx≡2(mod3),≡3(mod5),≡2(mod7)?We will solve this system, and with it Sun-Tsu's puzzle, later in this section. ◀
The Chinese remainder theorem states that when the moduli of a system of linear congruences are pairwise relatively prime, there is a unique solution of the system modulo the product of the moduli.
Proof: To establish this theorem, we need to show that a solution exists and that it is unique modulo m. We will show that a solution exists by describing a way to construct this solution; showing that the solution is unique modulo m is Exercise 30.
To construct a simultaneous solution, first let Mk=m/mk for k=1,2,…,n. That is, Mk is the product of the moduli except for mk. Because mi and mk have no common factors greater than 1 when i=k, it follows that gcd(mk,Mk)=1. Consequently, by Theorem 1, we know that there is an integer yk, an inverse of Mk modulo mk, such that Mkyk≡1(modmk). To construct a simultaneous solution, form the sum x=a1M1y1+a2M2y2+⋯+anMnyn. We will now show that x is a simultaneous solution. First, note that because Mj≡0(modmk) whenever j=k, all terms except the kth term in this sum are congruent to 0 modulo mk. Because Mkyk≡1(modmk) we see that x≡akMkyk≡ak(modmk), for k=1,2,…,n. We have shown that x is a simultaneous solution to the n congruences. ■
To solve the system of congruences in Example 4, first let m=3⋅5⋅7=105, M1=m/3=35, M2=m/5=21, and M3=m/7=15. We see that 2 is an inverse of M1=35 modulo 3, because 35⋅2≡2⋅2≡1(mod3); 1 is an inverse of M2=21 modulo 5, because 21≡1(mod5); and 1 is an inverse of M3=15(mod7), because 15≡1(mod7). The solutions to this system are those x such that
x≡a1M1y1+a2M2y2+a3M3y3=2⋅35⋅2+3⋅21⋅1+2⋅15⋅1=233≡23(mod105).It follows that 23 is the smallest positive integer that is a simultaneous solution. We conclude that 23 is the smallest positive integer that leaves a remainder of 2 when divided by 3, a remainder of 3 when divided by 5, and a remainder of 2 when divided by 7. ◀
Although the construction in Theorem 2 provides a general method for solving systems of linear congruences with pairwise relatively prime moduli, it can be easier to solve a system using a method known as back substitution. Example 6 illustrates the use of this method.
Use the method of back substitution to find all integers x such that x≡1(mod5), x≡2(mod6), and x≡3(mod7).
Solution: By Theorem 4 in Section 4.1, the first congruence can be rewritten as an equality, x=5t+1 where t is an integer. Substituting this expression for x into the second congruence gives 5t+1≡2(mod6). We can solve this congruence for t. First, subtract 1 from both sides to obtain 5t≡1(mod6). Because −1 is an inverse of 5 modulo 6 (as 5≡−1(mod6)), we multiply both sides by −1 to find t≡−1≡5(mod6). Using Theorem 4 in Section 4.1 again, we see that t=6u+5 where u is an integer. Substituting this expression for t back into the equation x=5t+1 tells us that x=5(6u+5)+1=30u+26. We insert this into the third equation to obtain 30u+26≡3(mod7). Solving this congruence tells us that u≡6(mod7). Hence, Theorem 4 in Section 4.1 tells us that u=7v+6 where v is an integer. Substituting this expression for u into the equation x=30u+26 tells us that x=30(7v+6)+26=210v+206. Translating this back into a congruence, we find the solution to the simultaneous congruences, x≡206(mod210). ◀
Suppose that m1,m2,…,mn are pairwise relatively prime moduli and let m be their product. By the Chinese remainder theorem, an integer a with 0≤a<m can be uniquely represented by the n-tuple consisting of its remainders upon division by mi,i=1,2,…,n. That is, we can uniquely represent a by (amodm1,amodm2,…,amodmn).
What are the pairs used to represent the nonnegative integers less than 12 when they are represented by the ordered pair where the first component is the remainder of the integer upon division by 3 and the second component is the remainder of the integer upon division by 4?
Solution: We have the following representations:
0123=(0,0)=(1,1)=(2,2)=(0,3)4567=(1,0)=(2,1)=(0,2)=(1,3)891011=(2,0)=(0,1)=(1,2)=(2,3).◀
To perform arithmetic with large integers, we select moduli m1,m2,…,mn, where each mi is an integer greater than 2, gcd(mi,mj)=1 whenever i=j, and m=m1m2…mn is greater than the results of the arithmetic operations we want to carry out.
Once we have selected our moduli, we carry out arithmetic operations with large integers by performing componentwise operations on the n-tuples representing these integers using their remainders upon division by mi,i=1,2,…,n. Once we have computed the value of each component in the result, we recover its value by solving a system of n congruences modulo mi,i=1,2,…,n. This method can be used to perform arithmetic with integers larger than can ordinarily be carried out on a computer, and computations with respect to the different moduli can be done in parallel, speeding up the arithmetic.
Suppose that performing arithmetic with integers less than 100 on a certain processor is much quicker than doing arithmetic with larger integers. We can restrict almost all our computations to integers less than 100 if we represent integers using their remainders modulo pairwise relatively prime integers less than 100. For example, we can use the moduli of 99, 98, 97, and 95. (These integers are relatively prime pairwise, because no two have a common factor greater than 1.)
By the Chinese remainder theorem, every nonnegative integer less than 99⋅98⋅97⋅95=89,403,930 can be represented uniquely by its remainders when divided by these four moduli. For example, we represent 123,684 as (33,8,9,89), because 123,684mod99=33;123,684mod98=8;123,684mod97=9; and 123,684mod95=89. Similarly, we represent 413,456 as (32,92,42,16).
To find the sum of 123,684 and 413,456, we add the 4-tuples componentwise and reduce each component with respect to the appropriate modulus:
(33,8,9,89)+(32,92,42,16)=(65mod99,100mod98,51mod97,105mod95)=(65,2,51,10).To find the sum, that is, the integer represented by (65,2,51,10), we need to solve the system of congruences
xxxx≡65(mod99),≡2(mod98),≡51(mod97),≡10(mod95).It can be shown that 537,140 is the unique nonnegative solution of this system less than 89,403,930. Consequently, 537,140 is the sum. ◀
Particularly good choices for moduli for arithmetic with large integers are sets of integers of the form 2k−1, where k is a positive integer, because it is easy to do binary arithmetic modulo such integers, and because it is easy to find sets of such integers that are pairwise relatively prime. For example, the integers 235−1,234−1,233−1,231−1,229−1, and 223−1 are pairwise relatively prime. Because the product of these six moduli exceeds 2184, we can perform arithmetic with integers as large as 2184 by doing arithmetic modulo each of these six moduli, none of which exceeds 235.
Fermat's little theorem is extremely useful in computing the remainders modulo p of large powers of integers, as Example 9 illustrates.
Find 7222mod11.
Solution: By Fermat's little theorem we know that 710≡1(mod11), so (710)k≡1(mod11) for every positive integer k. To take advantage of this last congruence, we divide the exponent 222 by 10, finding that 222=22⋅10+2. We now see that 7222=722⋅10+2=(710)2272≡(1)22⋅49≡5(mod11). It follows that 7222mod11=5. ◀
To find anmodp, where p is prime and p∤a, first use the division algorithm to find the quotient q and remainder r when n is divided by p−1, so that n=q(p−1)+r where 0≤r<p−1. It follows that an=aq(p−1)+r=(ap−1)qar≡1qar≡ar(modp). Hence, to find anmodp, we only need to compute armodp.
Unfortunately, there are composite integers n such that 2n−1≡1(modn). Such integers are called pseudoprimes to the base 2.
The integer 341 is a pseudoprime to the base 2 because it is composite (341=11⋅31) and 2340≡1(mod341). ◀
Given a positive integer n, determining whether 2n−1≡1(modn) is a useful test that provides some evidence concerning whether n is prime. If n does not satisfy this congruence, it is composite. If it does, it is either prime or a pseudoprime to the base 2. We can perform similar tests using bases b other than 2.
The integer 561 is a Carmichael number. To see this, first note that 561 is composite because 561=3⋅11⋅17. Next, note that if gcd(b,561)=1, then gcd(b,3)=gcd(b,11)=gcd(b,17)=1.
Using Fermat's little theorem we find that b2≡1(mod3),b10≡1(mod11),andb16≡1(mod17). It follows that
b560b560b560=(b2)280≡1(mod3),=(b10)56≡1(mod11),=(b16)35≡1(mod17).It follows that b560≡1(mod561) for all positive integers b with gcd(b,561)=1. Hence 561 is a Carmichael number. ◀
Determine whether 2 and 3 are primitive roots modulo 11.
Solution: When we compute the powers of 2 in Z11, we obtain 21=2,22=4,23=8,24=5,25=10,26=9,27=7,28=3,29=6,210=1. Because every element of Z11∗ is a power of 2, 2 is a primitive root of 11.
When we compute the powers of 3 modulo 11, we obtain 31=3,32=9,33=5,34=4,35=1. We note that this pattern repeats when we compute higher powers of 3. Because not all nonzero elements of Z11 are powers of 3, we conclude that 3 is not a primitive root of 11. ◀
An important fact in number theory is that there is a primitive root modulo p for every prime p. Suppose that p is prime and r is a primitive root modulo p. If a is an integer between 1 and p−1, that is, an element of Zp∗, there is a unique exponent e such that re=a in Zp, that is, remodp=a.
Find the discrete logarithms of 3 and 5 modulo 11 to the base 2.
Solution: When we computed the powers of 2 modulo 11 in Example 12, we found that 28=3 and 24=5 in Z11. Hence, the discrete logarithms of 3 and 5 modulo 11 to the base 2 are 8 and 4, respectively. We write log23=8 and log25=4 (where the modulus 11 is understood). ◀
The discrete logarithm problem takes as input a prime p, a primitive root r modulo p, and a positive integer a∈Zp; its output is the discrete logarithm of a modulo p to the base r. No polynomial-time algorithm is known for solving it. The difficulty of this problem plays an important role in cryptography, as we will see in Section 4.6.