SQUARE PATTERNS, FERMAT NUMBERS, AND FIBONACCI NUMBERS KEITH CONRAD 1. Introduction Numerical data suggest the following two patterns: 3 ≡ mod p ⇐⇒ p = 2, 3 or p ≡ 1, 11 mod 12, 5 ≡ mod p ⇐⇒ p = 2, 5 or p ≡ 1, 4 mod 5. Assuming these are true, we will use them together with Euler’s criterion to describe a primality test for Fermat numbers and to explain periodicity properties of the Fibonacci numbers mod p. 2. Determining primality of Fermat numbers n A Fermat number is an integer of the form Fn = 22 + 1, where n ≥ 0. The first six Fermat numbers are F0 = 3, F1 = 5, F2 = 17, F3 = 257, F4 = 65537, F5 = 4294967297. Fermat checked that Fn is prime for n = 0, 1, 2, 3, 4 and he conjectured that Fn is prime for all n. This was disproved when Euler showed F5 = 641 · 6700417, and in fact no further prime values of Fermat numbers have been found. The following necessary and sufficient condition for primality of Fermat numbers has been used to prove (with computers) that some Fermat numbers are composite. Theorem 2.1 (P´epin, 1877). For n ≥ 1, Fn is prime if and only if 3(Fn −1)/2 ≡ −1 mod Fn . Proof. First we show (3, Fn ) = 1 for n ≥ 1 by showing Fn ≡ 5 mod 12 for n ≥ 1. (This is not true for n = 0 since F0 = 3.) For any k ≥ 1, 4k ≡ 4 mod 12. Therefore n n−1 Fn = 22 + 1 = 42 + 1 ≡ 5 mod 12 when n ≥ 1. Suppose p := Fn is prime. Since p ≡ 5 mod 12 we have 3 6≡ mod p, so 3(p−1)/2 ≡ −1 mod p by Euler’s criterion. Now suppose, conversely, that 3(Fn −1)/2 ≡ −1 mod Fn . We want to prove Fn is prime. n Since Fn2−1 = 22 −1 , we have (2.1) Squaring both sides, 2n −1 32 ≡ −1 mod Fn . 2n 32 ≡ 1 mod Fn . n so the order of 3 mod Fn divides 22 . If the order is less, then it is 2e for some e ≤ 2n − 1. n 2n But e ≤ 2n − 1 ⇒ 2e |22 −1 , so 32 −1 ≡ 1 mod Fn , and this contradicts (2.1). Therefore n 3 mod Fn has order 22 = Fn − 1, so (Fn − 1)|ϕ(Fn ). Thus Fn − 1 ≤ ϕ(Fn ). The reverse 1 2 KEITH CONRAD inequality ϕ(Fn ) ≤ Fn −1 holds since ϕ(m) ≤ m−1 for all m ≥ 2. Therefore ϕ(Fn ) = Fn −1. That means every nonzero integer mod Fn is a unit mod Fn , so Fn is a prime number. Like Fermat’s compositeness test (if am−1 6≡ 1 mod m for some a from 1 to m − 1 then m is composite) when P´epin’s theorem shows Fn is composite it does not yield a non-trivial factor of Fn . For instance, P´epin’s theorem was used to prove F14 is composite in 1961, but a proper factor of F14 was not found until 2010. A year after P´epin’s work, Proth announced a result that is essentially a generalization. Theorem 2.2 (Proth, 1878). Let m = 2k ` + 1, where ` is odd and 2k > `. This number is prime if and only if there is an integer a such that a(m−1)/2 ≡ −1 mod m then m is prime. n A Fermat number 22 + 1 is 2k ` + 1 for k = 2n and ` = 1. P´epin’s theorem is slightly stronger than Proth’s theorem in this case because P´epin says we can definitely use a = 3, so Proth’s theorem is not strictly speaking a generalization of P´epin’s theorem. Proof. If m is prime then half the nonzero numbers mod m satisfy the condition a(m−1)/2 ≡ −1 mod m, so such a exist and in fact there are a lot of them. Conversely, assume some integer a satisfies a(m−1)/2 ≡ −1 mod m. We will prove m is prime by an argument based on [2]. The congruence a(m−1)/2 ≡ −1 mod m is the same as k−1 ` a2 (2.2) ≡ −1 mod m. k Squaring both sides, we get a2 ` ≡ 1 mod m. Therefore the order of a mod m divides 2k `, so it has the form 2e `0 , where e ≤ k and `0 is a factor of `. If e < k then 2e `0 |2k−1 `, so k−1 a2 ` ≡ 1 mod m. That contradicts (2.2), so e = k, so a mod m has order 2k `0 for some `0 dividing `. Therefore 2k |ϕ(m). We actually won’t use the divisibility relation 2k |ϕ(m) except as a template for the real argument we want to make. k−1 Let p be a prime factor of m. Since (2.2) implies a2 ` ≡ −1 mod p, running through the same argument as above with modulus p in place of modulus m shows 2k |ϕ(p). Since ϕ(p) = p − 1, we have p ≡ 1 mod 2k . In particular, every prime factor of m is greater than 2k . Therefore if m is not prime then m > 22k . However from the hypotheses of the theorem we have m = 2k ` + 1 ≤ 2k (2k − 1) + 1 = 22k − 2k + 1 < 22k , so we have a contradiction. Example 2.3. Let m = 31489. Then m − 1 = 31488 = 28 · 123 and 28 = 256 > 123. We have a(m−1)/2 ≡ 1 mod m for a = 2, 3, and 5, but 7(m−1)/2 ≡ −1 mod m, so m is prime by Proth’s theorem using a = 7. Proth’s theorem at first sight seems incredible: it lets us prove primality of m by verifying a congruence condition mod m for a single well-chosen a that should exist in great abundance if m really is prime. The catch is that m has to have a special form to apply Proth’s theorem: m needs to be odd with the highest power of 2 in m − 1 being greater than the odd part of m − 1. This is not typical of most odd numbers, or even most odd prime numbers. 3. Fibonacci numbers mod p Fibonacci numbers, denoted Fn but having nothing to do with Fermat numbers, start out as F1 = 1, F2 = 1, and Fn = Fn−1 + Fn−2 for n > 2. These numbers start out as 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, . . . . Reducing these mod 2, we get the sequence 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, . . . , SQUARE PATTERNS, FERMAT NUMBERS, AND FIBONACCI NUMBERS 3 which is periodic with period 3 and the periodic part is in bold. Reducing Fibonacci numbers mod 3, we get the sequence 1, 1, 2, 0, 2, 2, 1, 0, 1, 1, 2, 0, 2, 2, 1, 0, 1, 1, 2, 0, 2, 2, . . . . which is periodic with period 8. In the table below, the period of Fn mod p is listed for all primes p up to 137. p 2 3 5 7 11 13 17 19 23 29 31 period(Fn mod p) 3 8 20 16 10 28 36 18 48 14 30 p 37 41 43 47 53 59 61 67 71 73 79 period(Fn mod p) 76 40 88 32 108 58 60 136 70 148 78 p 83 89 97 101 103 107 109 113 127 131 137 period (Fn mod p) 168 44 196 50 208 72 108 76 256 130 276 For most primes p in the table, the period of Fn mod p is either p − 1 or 2(p + 1). Sometimes it is neither, but except for p = 5 the period of the Fibonacci sequence mod p is always a factor of p − 1 or 2(p + 1). The primes where the period is a factor of p − 1 are 11, 19, 29, 31, 41, 59, 61, 71, 79, 89, 101, 109, 131. The primes p where the period is a factor of 2(p + 1) are 2, 3, 7, 13, 17, 23, 37, 43, 47, 53, 67, 73, 83, 97, 103, 107, 113, 127, 137. Looking at these two lists, notice the pattern in the units digits: for the first case the primes all end in 1 or 9, and for the second case the primes other than 2 all end in 3 or 7. It is natural to conjecture, based on this evidence, that the Fibonacci sequence mod p has period dividing p − 1 when p ≡ 1, 9 mod 10 and period dividing 2(p + 1) when p ≡ 3, 7 mod 10. We will prove the pattern when p ≡ 1, 9 mod 10 using the rule for when 5 ≡ mod p. Theorem 3.1. For any prime p where p ≡ 1, 9 mod 10, the Fibonacci sequence mod p has period dividing p − 1. √ Proof. There is an explicit formula for the Fibonacci numbers using 5: √ !n √ !n ! 1+ 5 1− 5 1 (3.1) Fn = √ − . 2 2 5 This formula can be proved by induction: check the right side is 1 when n = 1 and n = 2, and then check the right side satisfies the as the Fibonacci numbers, √ √same linear recursion which comes down to the fact that (1 + 5)/2 and (1 − 5)/2 satisfy 1 + t = t2 . √ Although the right side of (3.1) is usually regarded as a formula √ for Fn where 5 is the real (positive) square root of 5, the right side makes sense when 5 is a square root of 5 anywhere that such a square root is invertible, including in the integers mod p if 5 ≡ mod p. That is, if 5 ≡ s2 mod p then the expression 1 1+s n 1−s n (3.2) − mod p s 2 2 makes sense and is Fn mod p. If p ≡ 1, 9 mod 10 then p ≡ 1, 4 mod 5, so 5 ≡ mod p and (3.2) is a formula for Fn mod p. The period of Fn mod p is the least k ≥ 1 such that ! 1 1 + s n+k 1 − s n+k 1 1+s n 1−s n (3.3) − ≡ − mod p s 2 2 s 2 2 4 KEITH CONRAD for all n. The numbers (1 + s)/2 and (1 − s)/2 that are being raised to powers are both nonzero mod p (since s 6≡ ±1 mod p, as s2 ≡ 5 6≡ 1 mod p), so by Fermat’s little theorem equation (3.3) at n = p − 1 simplifies to 1+s k 1−s k ≡ mod p, 2 2 and substituting this back into (3.3) for n = 1 implies 1+s k ≡ 1 mod p, 2 so 1+s k 1−s k (3.4) ≡ 1 mod p, ≡ 1 mod p. 2 2 Conversely, (3.4) implies (3.3) for all n ≥ 1, so the period of the Fibonacci sequence mod p is the least k ≥ 1 satisfying both congruences in (3.4). In other words, when p ≡ 1, 9 mod 10 the period of the Fibonacci sequence mod p is the least common multiple of the orders of (1 + s)/2 mod p and (1 − s)/2 mod p, where s2 ≡ 5 mod p. Both of these orders divide p − 1, so their least common multiple does as well. Example 3.2. Let p = 29. Since 5 ≡ 112 mod 29 we can use s = 11, so (1 + s)/2 = 6 and (1 − s)/2 = −5. The order of 6 mod 29 is 14 and the order of −5 mod 29 is 7. Therefore the Fibonacci sequence mod 29 has period 14, which is consistent with the table above. References [1] F. Proth, “Th´eor`emes sur les nombres premiers,” C. R. Acad. Sci. Paris, 87 (1878) 926. [2] R. Robinson, “The converse of Fermat’s theorem,” Amer. Math. Monthly 64 (1957), 703–710.

© Copyright 2017