Skip to main content

Linear Congruences and The Chinese Remainder Theorem

note

This is Lab 6 from Clint by Hugh Montgomery, edited by Elad Zelingher. All rights reserved to Hugh Montgomery.

Problem 1​

The program LinCon applies the extended Euclidean algorithm to find the complete solution set of the linear congruence ax≡b( mod m)a x \equiv b (\bmod m).

You now have two methods for finding solutions of linear congruences. You can use either (i) LinCon or (ii) PolySolv. Try both methods on the congruence 2x≡12 x \equiv 1 (mod 10000001). Which method takes longer to run? Estimate the running time for the two methods as a function of mm. Which method is asymptotically faster?

Problem 2​

Let mm and nn be given, and put g=gcd⁡(m,n)g=\gcd (m, n). The intersection of an arithmetic progression a( mod m)a(\bmod m) with an arithmetic progression b( mod n)b(\bmod n) is an arithmetic progression ( mod lcm(m,n))(\bmod \mathrm{lcm}(m, n)) if a≡b( mod g)a \equiv b (\bmod g), and is otherwise empty (Recall Problem 20 at the end of §2.3\S 2.3 of NZM.). The program IntAPTab presents these intersections in a manner reminiscent of the table on p. 68 of NZM. Rows are indexed by residues a( mod m)a(\bmod m), and columns by b( mod n)b(\bmod n). Run IntAPTab with parameters m=5,n=8m=5, n=8. Note that in the body of the table, each of the numbers 0,…,390, \ldots, 39 occurs exactly once. That is, the simultaneous congruences x≡a( mod 5),x≡b( mod 8)x \equiv a (\bmod 5), x \equiv b (\bmod 8) are equivalent to the single congruence x≡c( mod 40)x \equiv c (\bmod 40), for some suitable value of cc. The more general assertion that this is true whenever gcd⁡(m,n)=1\gcd (m, n)=1 is known as the Chinese Remainder Theorem (Theorem 2.18 of NZM). Take m=101,n=103m=101, n=103 in IntAPTab, and take a stroll around the table. There are now so many entries that it is no easy to see, by inspection, that each number 0,…,104020, \ldots, 10402 occurs exactly once in the body of the table. Now take m=102m=102, n=104n=104 in IntAPTab. What proportion of the entries are blank? Why? This phenomenon becomes more pronounced when gcd⁡(m,n)\gcd (m, n) is large. Try taking m=25,n=35m=25, n=35.

Problem 3​

The program CRT (meaning "Chinese Remainder Theorem") determines the intersection of two given arithmetic progressions. For example, the numbers xx such that both x≡3( mod 4)x \equiv 3(\bmod 4) and x≡2( mod 5)x \equiv 2(\bmod 5) are precisely the numbers for which x≡7x \equiv 7 ( mod 20)(\bmod 20). Run CRT with suitable parameters and watch the results. On the other hand, there are no xx for which both x≡1( mod 12)x \equiv 1(\bmod 12) and x≡19( mod 28)x \equiv 19(\bmod 28). To see why this is so, run CRT with suitable parameters.

Problem 4​

By repeated use of CRT, find a number xx such that 0<x<1090<x<10^{9} and none of xx, x+1x+1, …\ldots, x+6x+6 is squarefree. Thus we have a gap of length at least 8 between consecutive squarefree numbers. (Hint: What if x≡0( mod 4)x \equiv 0(\bmod 4), x≡−1( mod 9)x \equiv-1(\bmod 9), x≡−2( mod 25)x \equiv -2 (\bmod 25), x≡−3( mod 49)x \equiv -3 (\bmod 49), x≡−4( mod 121)x \equiv -4 (\bmod 121), x≡−5( mod 169)x \equiv -5 (\bmod 169), x≡−6( mod 289)x \equiv -6 (\bmod 289).) Apply the program Factor to each of the numbers xx, x+1x+1, …\ldots, x+6x+6 to verify your results. Are x−1x-1 and x+7x+7 both squarefree?

Problem 5​

Take m=15,n=13m=15, n=13 in IntAPTab. Note that an entry in the body of the table is printed in White if and only both the column and row labels of that entry are printed in White. More generally, if gcd⁡(m,n)=1,x≡a( mod m)\gcd (m, n)=1, x \equiv a(\bmod m), and x≡b( mod n)x \equiv b(\bmod n), then gcd⁡(c,mn)=1\gcd (c, m n)=1 if and only if gcd⁡(a,m)=1\gcd (a, m)=1 and gcd⁡(b,n)=1\gcd (b, n)=1. Hence the number of reduced residues ( mod mn)(\bmod m n) is the number of reduced residues ( mod m)(\bmod m) times the number of reduced residues ( mod n)(\bmod n). That is, ϕ(mn)=ϕ(m)ϕ(n)\phi(m n)=\phi(m) \phi(n) whenever (m,n)=1(m, n)=1. Since it is easy to see that ϕ(pα)=pα−pα−1=pα(1−1/p)\phi\left(p^{\alpha}\right)=p^{\alpha}-p^{\alpha-1}=p^{\alpha}(1-1 / p), we deduce that

ϕ(n)=∏pα∥n(pα−pα−1)=n∏p∣n(1−1p).\phi(n)=\prod_{p^{\alpha} \parallel n}\left(p^{\alpha}-p^{\alpha-1}\right)=n \prod_{p \mid n}\left(1-\frac{1}{p}\right) .

Thus we can calculate ϕ(n)\phi(n) easily, once the factorization of nn has been determined. The program Phi proceeds in this way: First the argument is factored, and then the above formula is used. Try using Phi for the input 42. You can confirm this answer by taking m=42m=42 in CngArTab, and viewing the multiplication table with only the reduced residues displayed.

Problem 6​

By using PolySolv, find two distinct residue classes x1x_{1} and x2x_{2} modulo 31 so that x3+x+1≡0( mod 31)x^{3}+x+1 \equiv 0 (\bmod 31). Similarly, find three distinct residue classes y1,y2,y3y_{1}, y_{2}, y_{3} modulo 47 so that x3+x+1≡0( mod 47)x^{3}+x+1 \equiv 0(\bmod 47). By using CRT, find six residue classes uu modulo 31⋅47=145731 \cdot 47=1457 so that u≡xi( mod 31)u \equiv x_{i} (\bmod 31) and u≡yj( mod 47),i=1,2,j=1,2,3u \equiv y_{j}(\bmod 47), i=1,2, j=1,2,3. Apply PolySolv with f(x)=x3+x+1,m=1457f(x)=x^{3}+x+1, m=1457. Interpret your findings. Note the conformity of this with Theorem 2.20 in NZM.

Problem 7​

Recall that the only solutions of x2≡1( mod p)x^{2} \equiv 1(\bmod p) are x≡±1( mod p)x \equiv \pm 1(\bmod p) (See Lemma 2.10 of NZM.). Given that 4757=67⋅714757=67 \cdot 71, use the program CRT to find four roots of the congruence x2≡1( mod 4757)x^{2} \equiv 1(\bmod 4757). Verify your results by using PolySolv. When mm is composite you now have two methods for locating all the roots of a polynomial congruence f(x)≡0( mod m)f(x) \equiv 0 (\bmod m). You can (i) apply PolySolv directly to the modulus mm, or (ii) factor mm into primepowers, apply PolySolv to each of these primepowers, and then use CRT to combine these solutions to construct the solutions modulo m. Estimate the running time of these two approaches. Which one is faster for a typical large composite number?