ForHosting KIT · Math

Wilson prime checker

5 is a Wilson prime: 4! + 1 = 25, which 5² divides exactly, leaving remainder 0. Enter a prime to see the exact remainder and whether this rare condition holds; only 5, 13 and 563 are known to pass. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Power (W)
5
You get
P squared
25
Remainder
0
Criterion
(p-1)! ≡ -1 (mod p^2)

The Wilson prime checker answers a precise modular question from elementary number theory: given a prime p, does p squared divide (p minus one) factorial plus one? Equivalently, is (p−1)! congruent to −1 modulo p²? Wilson's theorem already guarantees that every prime satisfies the same congruence modulo p, so the Wilson-prime condition is a genuine strengthening of the modulus rather than a new kind of primality test. Supply a prime p and the tool returns p, p squared, the exact remainder of (p−1)! The classic small Wilson primes are five and thirteen; five hundred sixty-three is the only other known Wilson prime and still sits comfortably inside the supported range. The engine multiplies successive integers under a BigInt modulus, never samples randomness, never reads the clock, and never leaves the process for a network call.

What a Wilson prime is and what you see

A Wilson prime is a prime number p such that p squared divides (p minus one) factorial plus one. In modular language the same statement reads (p−1)! ≡ −1 (mod p²).

Wilson's theorem says that for every prime p one already has (p−1)! ≡ −1 (mod p), so the factorial plus one is always divisible by p; the Wilson condition asks whether that divisibility lifts from modulus p all the way to modulus p². The only Wilson primes known in the literature are five, thirteen, and five hundred sixty-three; exhaustive searches far beyond one million have found no further examples, which makes the three-member list a favorite illustration of how rare modular liftings can be.

≡ -1 (mod p^2). If you only need ordinary primality, use a dedicated prime checker; this page answers the Wilson modular question with an explicit remainder.

How inputs are read and how the modular factorial stays exact

Optional leading plus signs are allowed for positive values; embedded spaces, hex prefixes, and exponential notation are rejected so a bad cell does not become a wrong flag. Internally the engine first proves primality by trial division up through the square root of p, which is cheap at this scale and fully deterministic.

It then walks the product two times three times four up through p minus one, reducing modulo p squared after every multiply with BigInt arithmetic so intermediate values never overflow a fixed machine word and never drift into floating-point territory. The final remainder of that product plus one modulo p squared is converted back to a safe JavaScript number—p squared is at most one trillion for the allowed range—and compared with zero.

Where Wilson checks fit in study, research demos, and code

Students meet Wilson primes when studying Wilson's theorem, modular arithmetic, and rare prime specializations alongside Sophie Germain primes, safeprimes, and Wilson quotients. Teachers can generate answer keys for worksheets without trusting opaque calculator apps that hide the modular product step or silently accept composites. Developers use the same contract to validate sample data for number-theory libraries, to gate property tests on random prime generators, or to pre-check that a demo seed is one of the three classic Wilson primes before a live presentation.

Contest practice often needs a fast offline source of Wilson answers so solutions can be checked without downloading OEIS tables or reimplementing BigInt factorial modular reduction under time pressure. Pair it with an ordinary prime checker when you need only primality, with a twin-prime checker when you need consecutive odd primes, and with modular-exponentiation tools when you need general pow-mod rather than a Wilson-specific factorial product.

Homework and contest classification

Decide whether given primes are Wilson primes for worksheets and contest checks by computing ((p−1)!+1) mod p² without hand factorial work.

Teaching Wilson's theorem liftings

Show students how Wilson's congruence mod p strengthens to mod p² while they change p live in the browser at no cost.

What does the Wilson prime checker cost?

It is free in your browser on this page.

What happens if p is not prime?

Wilson primes are defined only for primes; composites, 1, and non-integers are rejected with a clear message.

Which primes are Wilson primes?

The only known Wilson primes are 5, 13, and 563. This tool recomputes the modular criterion for any prime in range rather than looking up a hard-coded list.

Is the algorithm randomized?

No. It uses deterministic trial division for primality and exact BigInt modular multiplies for (p−1)! mod p². The same p always yields the same remainder and flag.

How is this different from a plain prime checker?

A prime checker only decides primality. This tool requires a prime and reports whether p² divides (p−1)!

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/numth/wilson-prime

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/numth/wilson-prime \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"p":5}'
{
  "p": 5
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "numth.wilson_prime",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

+1 modulo p², a boolean wilson_prime flag that is true only when that remainder is zero, and a short criterion string documenting the congruence.

What a Wilson prime is and what the response contains

Composites are excluded by definition: the property is only stated for primes, and this checker therefore rejects any non-prime input with invalid_input rather than returning a false negative that would confuse a homework key. On a successful call the response always includes the parsed prime p, the integer p_squared, the non-negative remainder of (p−1)! +1 modulo p_squared, the boolean wilson_prime equal to true exactly when that remainder is zero, and the criterion string (p-1)! A prime that fails the congruence is still a valid success with wilson_prime false—seven and eleven are everyday counterexamples—so absence of the Wilson property is never an error. Missing fields, non-integers, fractions, scientific notation, values outside two through one million, and composite integers fail with invalid_input and a clear message.

How inputs are read and how the modular factorial stays exact

The preferred field is p as a JSON integer, but decimal strings and the aliases prime, n, or value are accepted so forms, spreadsheets, and query strings can share one contract. The supported domain is the closed integer interval from two through one million: small enough that a linear modular product finishes quickly in a Worker or browser tab, and large enough to cover every known Wilson prime plus a wide band of classroom and contest examples.

Where Wilson checks fit in study, research demos, and code

On this page the work runs entirely in your browser; through the API each successful lookup costs $0.002, failed validation is not charged, and nothing is stored after the response returns. That split—free interactive exploration and a priced, identical API—matches the rest of the KIT tier-A catalog and lets you move from a classroom demo to an automated pipeline without changing the mathematical result.

Deterministic library fixtures

Assert that 5, 13, and 563 are Wilson primes and that nearby primes are not, with reproducible remainders for unit tests and CI.

Read the full KIT documentation →