Wilson prime

In number theory, a Wilson prime is a prime number $$p$$ such that $$p^2$$ divides $$(p-1)!+1$$, where "$$!$$" denotes the factorial function; compare this with Wilson's theorem, which states that every prime $$p$$ divides $$(p-1)!+1$$. Both are named for 18th-century English mathematician John Wilson; in 1770, Edward Waring credited the theorem to Wilson, although it had been stated centuries earlier by Ibn al-Haytham.

The only known Wilson primes are 5, 13, and 563. Costa et al. write that "the case $$p=5$$ is trivial", and credit the observation that 13 is a Wilson prime to. Early work on these numbers included searches by N. G. W. H. Beeger and Emma Lehmer, but 563 was not discovered until the early 1950s, when computer searches could be applied to the problem. If any others exist, they must be greater than 2&thinsp;×&thinsp;1013. It has been conjectured that infinitely many Wilson primes exist, and that the number of Wilson primes in an interval $$[x,y]$$ is about $$\log\log_x y$$.

Several computer searches have been done in the hope of finding new Wilson primes. The Ibercivis distributed computing project includes a search for Wilson primes. Another search was coordinated at the Great Internet Mersenne Prime Search forum.

Wilson primes of order $n$
Wilson's theorem can be expressed in general as $$(n-1)!(p-n)!\equiv(-1)^n\ \bmod p$$ for every integer $$n \ge 1$$ and prime $$p \ge n$$. Generalized Wilson primes of order $n$ are the primes $p$ such that $$p^2$$ divides $$(n-1)!(p-n)! - (-1)^n$$.

It was conjectured that for every natural number $n$, there are infinitely many Wilson primes of order $n$.

The smallest generalized Wilson primes of order $$n$$ are:

Near-Wilson primes
A prime $$p$$ satisfying the congruence $$(p-1)!\equiv -1+Bp\ (\operatorname{mod}{p^2})$$ with small $$|B|$$ can be called a near-Wilson prime. Near-Wilson primes with $$B=0$$ are bona fide Wilson primes. The table on the right lists all such primes with $$|B|\le 100$$ from up to 4.

Wilson numbers
A Wilson number is a natural number $$n$$ such that $$W(n)\equiv 0\ (\operatorname{mod}{n^2})$$, where $$W(n) = \pm1+\prod_\stackrel{1 \le k \le n}{\gcd(k,n)=1}{k},$$and where the $$\pm1$$ term is positive if and only if $$n$$ has a primitive root and negative otherwise. For every natural number $$n$$, $$W(n)$$ is divisible by $$n$$, and the quotients (called generalized Wilson quotients) are listed in. The Wilson numbers are

If a Wilson number $$n$$ is prime, then $$n$$ is a Wilson prime. There are 13 Wilson numbers up to 5.