Wilson's theorem says: n is prime iff (n−1)! ≡ −1 (mod n). This page computes the residue, explains why the theorem holds, and verifies it with harness tests.
We compute (n−1)! mod n exactly using modular multiplication. If the value equals n−1 (which is −1 mod n), Wilson predicts that n is prime. We also run a basic trial‑division primality cross‑check for modest n.
Each block computes (n−1)! mod n and checks Wilson's congruence. We also compare with a trial‑division primality test for small n.