Binary exponentiation An interesting class of problems of a computational nature ask for the standard residue of a power of a number, e.g., What are the last two digits of the number 2 284? In the absence of powerful software, it may be very difficult to compute this 86-digit number(!). Luckily, one can answer the question without this computation, since all we require is the standard residue mod 100 of the number. Computing powers mod m is an exercise in artful use of simple operations. In particular, to compute the standard residue a n mod m, we employ a process called binary exponentiation: express the exponent in binary form as a sum of powers of 2, then perform the computation by repeated squaring and reduction of residues. We illustrate with the example above. 2 284 = 2 256+16+8+4 = 2 28 +2 4 +2 3 +2 2 = 2 28 2 24 2 23 2 22 = 4 27 4 23 4 22 4 2 = 16 26 16 22 16 2 16
= 256 25 256 2 256 16 56 25 56 2 56 16 (mod100) 36 24 36 56 16 (mod100) 96 23 36 56 16 (mod100) 16 22 36 56 16 (mod100) 56 2 36 56 16 (mod100) 36 36 56 16 (mod100) 96 56 16 (mod100) 76 16 (mod100) 16 (mod100) Thus, the last two digits of 2 284 are 16. While this procedure is tedious for hand calculation, it is easily programmed into computational sofware.
The Exponential Structure of Arithmetic mod m: Fermat s Little Theorem As we saw in the discussion of the solution of polynomial congruences, the most basic congruences are those with prime moduli. The structure of arithmetic modulo a prime is the simplest of all forms of congruence. As we will see, when we work modulo a prime, the multiplicative structure of the arithmetic (which controls the computation of inverses, for instance) can be simplified considerably by expressing it in terms of the additive structure of powers of numbers, a discrete version of the idea of a logarithm. We provide a number of important and useful theorems that will build up to an explanation of this claim. Wilson s Theorem If p is prime, then (p 1)! 1 (mod p). Proof When p = 2, this is trivial; when p is odd, use the fact that every nonzero congurence class mod p, with the exception of the two classes for ±1, has a unique nonzero multiplicative inverse different from ±1. //
Without doubt, the most versatile result in all number theory is Fermat s Little Theorem (FlT) If p is prime and doesn t divide a, then a p 1 1 (mod p). Proof Let S = {1, 2,, p 1} and consider the map from S to S that sends x to the standard residue of ax mod p. This function is one-to-one, since ax ay (mod p) x y (mod p). But then, the function must also be onto, since domain and range have the same cardinality. It follows that {a,2a,,(p 1)a} is a complete residue system mod p. Therefore, 1 2 3 (p 1) a(2a)(3a) ((p 1)a) (mod p) or more simply, (p 1)! a p 1 (p 1)! (mod p). By Wilson s Theorem, this says that 1 a p 1 (mod p), or a p 1 1 (mod p). // Corollary If p is prime, then for all a, we have a p a (mod p). //
Corollary If p is prime and a n 1 (mod p), then a (n, p 1) 1 (mod p). Proof For suitable integers x and y, we can write a (n, p 1) a nx +( p 1)y (a n ) x (a p 1 ) y 1 x 1 y 1 (mod p).// If n is the smallest positive integer for which a n 1 (mod p), we call n the order of a mod p. Corollary The order of a mod p divides p 1. Proof If n is the order of a mod p, then a n 1 (mod p). But then a (n, p 1) 1 (mod p) as well. But since (n, p 1) n and n is the smallest positive integer for which a n 1 (mod p), we must have (n, p 1) = n, whence n p 1. // Fermat formulated his Little Theorem in the course of investigating the primality of the Mersenne numbers M n = 2 n 1. If p is a prime factor of M n, then 2 n 1 (mod p). If in addition, n is prime (recall that if n is composite, then necessarily, M n is composite), then the last corollary asserts that 2 (n, p 1) 1 (mod p), and since we cannot then have (n, p 1) = 1, it must be that (n, p 1) = n, that is, n p 1. But p must be odd, so n is as well, and we can conclude more strongly that 2n p 1. We have proven the
Corollary If n is prime and p is a prime factor of the Mersenne number M n = 2 n 1, then p 1 (mod 2n). // Corollary There are infinitely many primes of the form p 1 (mod 8). Proof Suppose there are only finitely many such primes: p 1, p 2,, p k. Let N = (2p 1 p 2 p k ) 4 +1. If p is a prime factor of N, then (*) (2p 1p 2 p k ) 4 1 (mod p), so (2p 1 p 2 p k ) 8 1 (mod p). But then (2p 1 p 2 p k ) (8, p 1) 1 (mod p). However, (8, p 1) must be one of 1, 2, 4, or 8. Because of (*), we must exclude 1, 2, 4 as options. This means that (8, p 1) = 8, whence 8 p 1, or p 1 (mod 8). But then p must be one of the listed primes above, therefore (*) yields the absurd statement that 0 1(mod p). // Corollary If n is a sum of two relatively prime squares, then every odd prime factor p of n satisfies p 1 (mod 4).
Proof Suppose n = a 2 +b 2 with (a,b ) = 1 and p is an odd prime factor. Then, since p a 2 +b 2, neither a nor b can be multiples of p. So a 2 +b 2 0 (mod p) a 2 b 2 (mod p) ( a 2 ) 1 2 ( p 1) (b 2 ) 1 2 ( p 1) (mod p) ( 1) 1 2 ( p 1) a p 1 b p 1 (mod p) which, using FlT, implies ( 1) 1 2 ( p 1) 1 (mod p). But if p 3 (mod4), then 1 (p 1) is an odd integer, so 2 ( 1) 1 2 ( p 1) = 1, which implies the impossible condition 1 1 (mod p). Therefore we must have p 1 (mod 4). // Corollary If p is an odd prime, then the congruence x 2 1(mod p) has the two solutions x ±[ 1 (p 1)]! (mod p) if p 1 (mod 4), but no 2 solutions if p 3 (mod4). Proof If x 2 1(mod p) is solvable, then p divides the number x 2 +1 with (x,1) = 1, so by the previous result, p 1 (mod 4). To show that the given values of x solve the congruence, put a = [ 1 (p 1)]!; then, it 2 suffices to show that a 2 1(mod p). Clearly, a is a
factor of (p 1)!. If b is the integer for which ab = (p 1)!, then So 1 ( p 1) 2 b = (a +1)(a + 2) (p 2)(p 1) = (p j). 1 ( p 1) 2 b ( j ) ( 1) 1 2 ( p 1) [ 1 (p 1)]! 2 ( 1)1 2 ( p 1) a (mod p), j=1 j=1 and since p 1 (mod 4), we have ( 1) 1 2 ( p 1) = 1, so b a (mod p). It follows that a 2 ab (p 1)! 1 (mod p). //