Wilson Prime Calculator

Primes

is 5 a Wilson prime?Yes - (p - 1)! is congruent to -1 mod 25
(p - 1)! mod p^224
value needed for a Wilson prime, p^2 - 124
Wilson quotient ((p - 1)! + 1) / p^21
How this was calculated
  1. Wilson's theorem says (p - 1)! is congruent to -1 mod p for every prime; a Wilson prime strengthens the modulus to p^2 = 25.
  2. Multiply 1 x 2 x ... x 4 keeping only the residue mod 25: the factorial residue is 24.
  3. Compare with p^2 - 1 = 24: they match, so the Wilson quotient is a whole number and the prime is a Wilson prime.
  4. Only three Wilson primes are known - 5, 13 and 563 - and searches far beyond this range have found no others.

Wilson's theorem is one of the gems of elementary number theory: for every prime p, (p - 1)! is congruent to -1 modulo p. A Wilson prime is a prime that passes a much stronger version of the same test - the congruence must hold modulo p squared, not just modulo p. The strengthening sounds minor and is anything but: among all primes ever tested, only three pass.

This calculator runs the strengthened test exactly. It accumulates the factorial residue modulo p^2, compares it with the required residue p^2 - 1, and reports the Wilson quotient ((p - 1)! + 1) / p^2 - which is a whole number exactly when the prime is a Wilson prime. The known answers frame the page: 5 passes, 13 passes with quotient 2,834,329, and 7 fails with residue 34 where 48 was required.

Composites are rejected before the test, because Wilson's theorem is a statement about primes - the calculator shows the factorization instead. If you want to see the congruence succeed, enter 5 or 13; if you want to see how an ordinary prime fails, enter 7 or any other prime and compare the residue with its target.

Worked examples

Is 5 a Wilson prime?

(5)

is 5 a Wilson prime?Yes - (p - 1)! is congruent to -1 mod 25
(p - 1)! mod p^224
value needed for a Wilson prime, p^2 - 124
Wilson quotient ((p - 1)! + 1) / p^21

Is 13 a Wilson prime?

(13)

is 13 a Wilson prime?Yes - (p - 1)! is congruent to -1 mod 169
(p - 1)! mod p^2168
value needed for a Wilson prime, p^2 - 1168
Wilson quotient ((p - 1)! + 1) / p^22,834,329

Is 7 a Wilson prime?

(7)

is 7 a Wilson prime?No - (p - 1)! mod 49 is 34, not 48
(p - 1)! mod p^234
value needed for a Wilson prime, p^2 - 148
Wilson quotient ((p - 1)! + 1) / p^2not a whole number - (p - 1)! + 1 leaves residue 35 mod p^2

From Wilson's theorem to Wilson primes

Wilson's theorem says (p - 1)! = -1 (mod p) for prime p, and the converse holds too, making it a complete primality criterion in principle. The Wilson prime definition upgrades the modulus: p is a Wilson prime when (p - 1)! = -1 (mod p^2). Every Wilson prime is prime, but almost no prime is a Wilson prime - the stronger congruence is a coincidence that has been observed exactly three times.

For p = 5 the arithmetic is small enough to check by hand: (5 - 1)! = 24, and 24 = -1 (mod 25) because 24 - (-1) = 25. So 5 passes. For p = 7: (7 - 1)! = 720, and 720 mod 49 is 34, while the target is 48. The miss is not close in any useful sense - the residue is essentially arbitrary for non-Wilson primes, and 7 is an ordinary prime as far as this test is concerned.

The calculator mirrors the hand computation at scale: it multiplies 1 x 2 x ... x (p - 1) keeping only the residue modulo p^2 at each step, so the numbers never explode, and compares the final residue with p^2 - 1.

  • Wilson's theorem: (p - 1)! = -1 (mod p) for every prime p
  • Wilson prime: the same congruence modulo p^2
  • 5 passes (24 = -1 mod 25); 7 fails (residue 34, target 48)
  • Known Wilson primes: 5, 13, 563 - only three

The Wilson quotient

The Wilson quotient packages the test into a single number: W(p) = ((p - 1)! + 1) / p^2. Wilson's theorem guarantees p divides (p - 1)! + 1; the quotient asks whether p^2 does. When it does, W(p) is an integer and p is a Wilson prime; when it does not, the division leaves a remainder and the calculator reports that remainder instead.

At p = 13 the quotient is exactly 2,834,329 - a whole number emerging from a 12-digit factorial is the whole content of 13's Wilson status. At p = 7 the division (720 + 1) / 49 leaves residue 35 (that is, (p - 1)! + 1 = 721 = 14 x 49 + 35), so the quotient is not a whole number and 7 fails. The two examples show the test's binary character: there is no 'nearly Wilson' - the quotient is integral or it is not.

Quotients also give the search its bookkeeping: scanning primes for Wilson primes means computing W(p) modulo p for each candidate p and checking for 0, which is what large searches actually do.

  • W(13) = 2,834,329 exactly - an integer, so 13 is a Wilson prime
  • At p = 7, (p - 1)! + 1 leaves residue 35 mod 49 - not divisible
  • The test is binary: the quotient is a whole number or it is not

Only three are known

The complete list of known Wilson primes is 5, 13 and 563. The gap structure is part of the fascination: 13 to 563 is already a jump, and after 563 - nothing, despite searches that have swept the primes far beyond 10^13. Heuristics suggest Wilson primes should be infinitely many but vanishingly sparse - roughly log log x of them up to x - so the known trio is consistent with a family that continues at a glacial pace.

The search difficulty is real computation, not theory: for each prime p the factorial residue modulo p^2 must be accumulated, and the cost grows with p. Modern searches use clever product trees and remainder algorithms to push the frontier, but the frontier advances slowly, and 563 has been the largest known Wilson prime for decades of computing progress.

For the reader, the practical upshot is that the calculator's verdicts at small primes are not provisional: 5 and 13 pass, everything else you are likely to type fails, and 563 is there to be confirmed if you want to see the third success.

Prime(p - 1)! mod p^2Target p^2 - 1Wilson prime?
52424Yes
73448No
13168168Yes
563p^2 - 1316,968Yes - the largest known

How the calculator tests a prime

Two stages run in order. First, primality: a composite input is factored and rejected, with the factorization shown, because the Wilson test is only defined for primes. Second, the residue accumulation: starting from 1, multiply by each integer from 2 to p - 1, reducing modulo p^2 after every step. The final residue is compared with p^2 - 1, and the Wilson quotient (or its remainder) is computed from a full big-integer factorial when the verdict needs it.

Reducing at every step is what makes the test feasible at all: (p - 1)! itself has thousands of digits for p in the hundreds, but the residue modulo p^2 never exceeds six digits for p up to 1,000. The method is exact - no floating point, no approximation - so a 'Yes' from this page is a proof for that prime, not an estimate.

  • Stage 1: primality, with factorization shown for composites
  • Stage 2: factorial residue accumulated modulo p^2, compared with p^2 - 1
  • Exact integer arithmetic throughout - a Yes is a proof for that prime

Wilson primes among the congruence celebrities

Wilson primes belong to a small club of primes defined by strengthened congruences. Wieferich primes strengthen Fermat's little theorem the same way (2^(p-1) = 1 mod p^2) and are almost as rare - only 1093 and 3511 are known. Wall-Sun-Sun primes strengthen a Fibonacci congruence and none are known at all. The pattern is a general phenomenon: squaring the modulus of a classical congruence turns a theorem into a treasure hunt.

That is the right way to read this page's headline fact. 'Only three known' is not a failure of effort; it is the expected shape of a mod-p^2 condition, and it is why each of 5, 13 and 563 has a name-like status among primes. Testing your favourite prime here takes a second, and the near-certain 'No' you get is the normal state of primes under this lens.

One more relative deserves a footnote: Wilson's theorem itself generalizes - the concept of a Wilson number and the behaviour of the quotient (p - 1)! + 1 over composite moduli are studied under the name of Wilson quotients for general n. The prime case on this page is the sharp one, because Wilson's theorem characterizes primality; for composites the congruence fails almost always, and the rare exceptions form their own small research topic. The calculator stays with primes, where the strengthened congruence picks out 5, 13 and 563 from the crowd.

Try 563: the third and largest known Wilson prime. Its target residue is 316,968 - and the factorial residue meets it exactly.

Why the search is hard, and why it continues

Heuristics predict the Wilson primes should be infinite but extraordinarily sparse - on the order of log log x of them up to x. At the scale of current searches, that prediction expects roughly two or three in range, which is exactly what has been found: the trio 5, 13, 563 is neither suspiciously many nor suspiciously few. The next one, if the heuristic is honest, hides at a height where the factorial computation per candidate prime is a serious piece of engineering.

The computational obstacle is the residue itself. Testing one prime p means multiplying out (p - 1)! modulo p^2 - p multiplications of numbers up to p^2 - and a search must do this for every prime in its range. Product-tree and remainder-tree techniques batch the work dramatically, yet the frontier has crept rather than leapt, and each extension of the search range is a publishable computation in its own right.

Meanwhile the concept keeps generating relatives. Wilson quotients can be asked of every prime - the quotient is 0 modulo p exactly for Wilson primes - and the distribution of nonzero quotients is itself studied, as is the analogous question for the other classical congruences. A prime that fails this page's test is not uninteresting; it is a data point in the quotient's statistics.

  • Heuristic density: about log log x Wilson primes up to x - three in range is on prediction
  • Searches batch factorial residues with product and remainder trees
  • The Wilson quotient's behaviour at ordinary primes is studied in its own right

FAQs

What is a Wilson prime?

A prime p where (p - 1)! is congruent to -1 modulo p^2 - Wilson's theorem with the modulus strengthened from p to p^2. Only three are known: 5, 13 and 563.

How many Wilson primes are known?

Only three: 5, 13 and 563. Searches far beyond 10^13 have found no others, and heuristics suggest they continue only at a glacial pace.

Is 7 a Wilson prime?

No. (7 - 1)! mod 49 is 34, not the required 48, and its Wilson quotient is not a whole number - (p - 1)! + 1 leaves residue 35 mod 49.

What is the Wilson quotient of 13?

Exactly 2,834,329. The fact that ((13 - 1)! + 1) / 169 comes out whole is precisely what makes 13 a Wilson prime.

Is 5 a Wilson prime?

Yes. (5 - 1)! = 24, and 24 is congruent to -1 modulo 25, so 5 passes the strengthened test - it is the smallest Wilson prime.

Can a composite number be a Wilson prime?

No. The test is only defined for primes, since Wilson's theorem itself is a primality statement. The calculator factors composite inputs and rejects them before the residue test.

Sources

Related calculators

Chen Prime Calculator
Check whether a prime is a Chen prime - p where p + 2 is prime or semiprime - or list Chen primes up to a limit.
Circular Prime Calculator
Test whether a number is a circular prime - prime under every cyclic rotation of its digits - listing all rotations and the next circular prime.
Cousin Prime Calculator
Count cousin prime pairs - primes differing by 4 - up to a limit by sieve, with the largest pair in range and the twin-prime count at the same limit for comparison.