The OEIS Foundation is supported by donations from users of the OEIS and by a grant from the Simons Foundation.



(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A007540 Wilson primes: primes p such that (p-1)! == -1 (mod p^2).
(Formerly M3838)
5, 13, 563 (list; graph; refs; listen; history; text; internal format)



Suggested by the Wilson-Lagrange Theorem: An integer p > 1 is a prime if and only if (p-1)! == -1 (mod p). Cf. Wilson quotients, A007619.

Sequence is believed to be infinite. Next term is known to be > 2*10^13.

Intersection of the Wilson numbers A157250 and the primes A000040. - Jonathan Sondow, Mar 04 2016

Conjecture: Odd primes p such that 1^(p-1) + 2^(p-1) + ... + (p-1)^(p-1) == p-1 (mod p^2). - Thomas Ordowski and Giovanni Resta, Jul 25 2018

From Felix Fröhlich, Nov 16 2018: (Start)

Harry S. Vandiver apparently said about the Wilson primes "It is not known if there are infinitely many Wilson primes. This question seems to be of such a character that if I should come to life any time after my death and some mathematician were to tell me that it had definitely been settled, I think I would immediately drop dead again." (cf. Ribenboim, 2000, p. 217).

Let p be a Wilson prime and let i be the index of p in A000040. For n = 1, 2, 3, the values of i are 3, 6, 103. The primes among those values are Lerch primes, i.e., terms of A197632. Is this a property that necessarily follows if i is prime (cf. Sondow, 2011/2012, 2.5 Open Problems 5)? (End)


A. H. Beiler, Recreations in the Theory of Numbers, Dover, NY, 1964, p. 52.

C. Clawson, Mathematical Mysteries, Plenum Press, 1996, p. 180.

R. Crandall and C. Pomerance, Prime Numbers: A Computational Perspective, Springer, NY, 2001; see p. 29.

G. H. Hardy and E. M. Wright, An Introduction to the Theory of Numbers, 5th ed., Oxford Univ. Press, 1979, th. 80.

P. Ribenboim, My Numbers, My Friends: Popular Lectures on Number Theory, Springer Science & Business Media, 2000, ISBN 0-387-98911-0.

P. Ribenboim, The Book of Prime Number Records. Springer-Verlag, NY, 2nd ed., 1989, p. 277.

N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

I. Vardi, Computational Recreations in Mathematica. Addison-Wesley, Redwood City, CA, 1991, p. 73.

D. Wells, The Penguin Dictionary of Curious and Interesting Numbers. Penguin Books, NY, 1986, 163.


Table of n, a(n) for n=1..3.

Edgar Costa, Robert Gerbicz, and David Harvey, A search for Wilson primes, arXiv:1209.3436 [math.NT], 2012.

Edgar Costa, Robert Gerbicz, and David Harvey, A search for Wilson primes, Math. Comp. 83 (2014), pp. 3071-3091.

James Grime and Brady Haran, What do 5, 13 and 563 have in common?, YouTube video (2014).

E. Lehmer, "On congruences involving Bernoulli numbers and the quotients of Fermat and Wilson". Annals of Mathematics 39 (2): 350-360 (1938). doi:10.2307/1968791.

Tapio Rajala, Status of a search for Wilson primes

Maxie D. Schmidt, New Congruences and Finite Difference Equations for Generalized Factorial Functions, arXiv:1701.04741 [math.CO], 2017.

J. Sondow, Lerch Quotients, Lerch Primes, Fermat-Wilson Quotients, and the Wieferich-Non-Wilson Primes 2, 3, 14771, In: M. B. Nathanson, Combinatorial and Additive Number Theory, Springer, CANT 2011 and 2012. Also on arXiv, arXiv:1110.3113 [math.NT], 2011-2012.

Apoloniusz Tyszka, On sets X subset of N for which we know an algorithm that computes a threshold number t(X) in N such that X is infinite if and only if X contains an element greater than t(X), 2019.

Eric Weisstein's World of Mathematics, Wilson Prime

Eric Weisstein's World of Mathematics, Integer Sequence Primes

Wikipedia, Wilson prime

P. Zimmermann, Records for prime numbers


Select[Prime[Range[500]], Mod[(# - 1)!, #^2] == #^2 - 1 &] (* Harvey P. Dale, Mar 30 2012 *)


(PARI) forprime(n=2, 10^9, if(Mod((n-1)!, n^2)==-1, print1(n, ", "))) \\ Felix Fröhlich, Apr 28 2014

(PARI) is(n)=prod(k=2, n-1, k, Mod(1, n^2))==-1 \\ Charles R Greathouse IV, Aug 03 2014


from sympy import prime

A007540_list = []

for n in range(1, 10**4):

    p, m = prime(n), 1

    p2 = p*p

    for i in range(2, p):

        m = (m*i) % p2

    if m == p2-1:

        A007540_list.append(p) # Chai Wah Wu, Dec 04 2014


Cf. A007619, A157249, A157250.

Sequence in context: A122900 A145557 A012033 * A290171 A157250 A009157

Adjacent sequences:  A007537 A007538 A007539 * A007541 A007542 A007543




N. J. A. Sloane



Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recent
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified July 8 22:01 EDT 2020. Contains 335537 sequences. (Running on oeis4.)