MATHEMATICS OF COMPUTATION Volume 66, Number 217, January 1997, Pages 433–449 S 0025-5718(97)00791-6 A SEARCH FOR WIEFERICH AND WILSON PRIMES RICHARD CRANDALL, KARL DILCHER, AND CARL POMERANCE Abstract. An odd prime p is called a Wieferich prime if 2 p1 1 (mod p 2 ); alternatively, a Wilson prime if (p - 1)! ≡-1 (mod p 2 ). To date, the only known Wieferich primes are p = 1093 and 3511, while the only known Wilson primes are p =5, 13, and 563. We report that there exist no new Wieferich primes p< 4 × 10 12 , and no new Wilson primes p< 5 × 10 8 . It is elementary that both defining congruences above hold merely (mod p), and it is sometimes estimated on heuristic grounds that the “probability” that p is Wieferich (independently: that p is Wilson) is about 1/p. We provide some statistical data relevant to occurrences of small values of the pertinent Fermat and Wilson quotients (mod p). 0. Introduction Wieferich primes figure strongly in classical treatments of the first case of Fer- mat’s Last Theorem (“FLT(I)”). For an odd prime p not dividing xyz , Wieferich [26] showed that x p + y p + z p = 0 implies 2 p-1 1 (mod p 2 ). Accordingly, we say that an odd prime p is a Wieferich prime if the Fermat quotient q p (2) = 2 p-1 1 p vanishes (mod p). The small Wieferich primes p = 1093 and 3511 have long been known. Lehmer [16] established that there exist no other Wieferich primes less than 6 × 10 9 , and David Clark [6] recently extended this upper bound to 6.1 × 10 10 . This paper reports extension of the search limit to 4 × 10 12 , without a single new Wieferich prime being found. The authors searched to 2 × 10 12 . David Bailey used some of our techniques (and some machine-dependent techniques of his own; see §4: Machine considerations) to check our runs to 2 × 10 12 , and to extend the search to the stated limit of 4 × 10 12 . Richard McIntosh likewise verified results over several long intervals. Wilson’s classical theorem, that if p is prime, then (p 1)! ≡−1 (mod p), and Lagrange’s converse, that this congruence characterizes the primes, are certainly Received by the editor May 19, 1995 and, in revised form, November 27, 1995 and January 26, 1996. 1991 Mathematics Subject Classification. Primary 11A07; Secondary 11Y35, 11–04. Key words and phrases. Wieferich primes, Wilson primes, Fermat quotients, Wilson quotients, factorial evaluation. The second author was supported in part by a grant from NSERC. The third author was supported in part by an NSF grant. c 1997 American Mathematical Society 433