Pillai Prime Calculator
Prime
- A Pillai prime is a prime p for which some n makes n! (n factorial) congruent to -1 mod p, while p is not congruent to 1 mod n.
- Running the factorials mod p: n! mod 23 first reaches 22 (that is, -1 mod p) at n = 14.
- Checking the side condition at that witness: 23 mod 14 = 9, which is not 1, so the witness counts.
- Verdict: 23 is a Pillai prime. The Pillai primes begin 23, 29, 59, 61, 67, 71 and 79, and they are tied to how factorials behave modulo a prime.
This Pillai prime calculator checks whether a prime p is a Pillai prime. A Pillai prime is a prime p for which some n has n! congruent to -1 mod p, while p is not congruent to 1 mod n. The calculator tests the candidates and reports the smallest witness n that satisfies both conditions, or tells you that no such n exists below p. For example, 23 is a Pillai prime: the smallest witness is n = 14, with 14! congruent to -1 mod 23 and 23 mod 14 = 9. Likewise, 29 is a Pillai prime with smallest witness n = 18, where 29 mod 18 = 11. Not every prime qualifies: 19 is prime but not a Pillai prime, because no n below 19 satisfies both conditions. The Pillai primes begin 23, 29, 59, 61, 67, 71 and 79.
The page shows the formula and the step-by-step workings behind every result, so you can follow each congruence check yourself rather than trusting a black box. Worked examples, including the 23 and 29 cases above, show how the smallest witness is found and how a prime such as 19 is ruled out. Because the method applies the definition of a Pillai prime directly to each candidate, it is the accepted standard for this kind of calculation. Sources are listed so you can verify the definition and the sequence of Pillai primes independently.
Worked examples
23 is a Pillai prime with witness 14
(23)
| Pillai prime | Yes |
| Smallest witness n | 14 |
| n! mod p at the witness | 22 |
| p mod n at the witness | 9 |
29 is a Pillai prime with witness 18
(29)
| Pillai prime | Yes |
| Smallest witness n | 18 |
| n! mod p at the witness | 28 |
| p mod n at the witness | 11 |
19 is prime but not a Pillai prime
(19)
| Pillai prime | No |
| Smallest witness n | No witness below p |
| n! mod p at the witness | Never qualifies |
| p mod n at the witness | - |
What is a Pillai prime?
A Pillai prime is defined by two conditions that must hold together. The first is a factorial congruence: a prime p qualifies when some positive integer n has n! congruent to −1 modulo p. The second is a side condition: p must not be congruent to 1 modulo n. Both parts matter, and the definition is only interesting because they are combined. A Pillai prime calculator checks these two requirements at once, which is why it is a more useful tool than a simple prime checker.
The first condition alone is far too easy to satisfy. For any prime p, Wilson's theorem guarantees that (p − 1)! is congruent to −1 modulo p, so every prime would pass if the factorial congruence were the only test. The side condition is what removes this trivial case and gives the definition its bite. Requiring that p is not congruent to 1 modulo n rules out the most obvious witnesses and forces the search toward genuinely special pairs of p and n. A prime that fails either condition is simply not a Pillai prime, no matter how the factorial behaves.
The smallest example shows how the two conditions work together. The number 23 is a Pillai prime, and its smallest witness is n = 14. For that pair, 14! is congruent to −1 modulo 23, so the factorial congruence holds. At the same time, 23 mod 14 equals 9, which is not 1, so the side condition holds as well. The next Pillai prime is 29, with smallest witness n = 18; there, 29 mod 18 equals 11, again not 1. In both cases the witness n is smaller than p, and the remainder is something other than 1.
Contrast these with 19, which is prime but not a Pillai prime. No n below 19 satisfies both conditions, so 19 does not appear in the sequence. This example is useful because it shows that being prime is not enough: the factorial congruence and the side condition must both be met by some n. The Pillai primes begin 23, 29, 59, 61, 67, 71 and 79, and each of these entries earned its place by passing both tests.
The side condition also explains why the notion is considered interesting rather than a restatement of Wilson's theorem. Without it, the definition would collapse into a trivial property shared by every prime. With it, the Pillai primes form a sparser and less obvious list, and the smallest witness for each prime becomes a meaningful piece of information. When you use a Pillai prime calculator, it is checking the factorial congruence and the side condition together, so a result of "not a Pillai prime" can mean either condition failed.
- Factorial congruence: some n has n! congruent to −1 mod p.
- Side condition: p is not congruent to 1 mod n.
- 23: smallest witness n = 14, with 14! congruent to −1 mod 23 and 23 mod 14 = 9.
- 29: smallest witness n = 18, with 29 mod 18 = 11.
- 19: prime, but no n below 19 satisfies both conditions.
- The Pillai primes begin 23, 29, 59, 61, 67, 71 and 79.
Worked examples
The fastest way to see how a Pillai prime calculator works is to run the factorial search on a small prime and watch for the moment both conditions line up. Take p = 23. The calculator steps through n = 1, 2, 3, and so on, computing n! modulo 23 at each stage and checking two things: whether the residue equals -1 (that is, 22 mod 23), and whether 23 mod n is different from 1. The first n that satisfies both is the smallest witness. For 23, that witness is n = 14: 14! is congruent to -1 mod 23, and 23 mod 14 = 9, which is not 1. So 23 qualifies as a Pillai prime, and the search stops at 14.
The same procedure on p = 29 gives a smallest witness of n = 18. There, 18! is congruent to -1 mod 29, and 29 mod 18 = 11, again not 1. Both conditions hold, so 29 is a Pillai prime. Notice that the witness is not simply p - 1; the calculator has to test each n in order rather than assume where the match will appear. That is exactly why a dedicated Pillai prime calculator is useful: it does the modular factorial arithmetic and the divisibility check side by side, so you can see the witness rather than guess it.
Now compare a prime that fails. 19 is prime, but it is not a Pillai prime: no n below 19 satisfies both conditions. Running the search on 19 is instructive because the factorial residues do reach -1 at some n, yet the second condition never holds at the same time within the range tested. The definition requires both parts together — n! congruent to -1 mod p and p not congruent to 1 mod n — so a near-miss on either count is not enough. Primality alone does not make a Pillai prime; the witness has to clear both tests.
These three runs also show where the sequence begins. The Pillai primes start 23, 29, 59, 61, 67, 71 and 79, so 23 and 29 are the first two entries, and 19 is correctly absent from the list. If you want to check a prime of your own, enter it into the Pillai prime calculator and read the smallest witness it reports, along with the value of p mod n, to confirm both conditions were met.
| Prime p | Smallest witness n | p mod n | Pillai prime? |
|---|---|---|---|
| 23 | 14 | 9 | Yes |
| 29 | 18 | 11 | Yes |
| 19 | None below 19 | — | No |
Why the side condition matters
The definition of a Pillai prime has two parts, and the second one is easy to skim past. A prime p qualifies when some n makes n! congruent to -1 mod p, but only if p is also not congruent to 1 mod n. Drop that side condition and the concept collapses into something far less interesting. A Pillai prime calculator should therefore check both requirements, not just the factorial congruence, because a number that satisfies only the first part is not a Pillai prime.
The reason is the Wilson-theorem style case. Wilson's theorem says that for a prime p, (p - 1)! is congruent to -1 mod p. So if you set n = p - 1 and ignore the side condition, every prime would automatically have a witness, since (p - 1)! is congruent to -1 mod p by Wilson's theorem alone. That would make every prime a Pillai prime and the definition would say nothing distinctive. The requirement that p is not congruent to 1 mod n blocks this shortcut: when n = p - 1, p is congruent to 1 mod (p - 1), so that witness is disqualified. The side condition is what forces the search toward genuinely different values of n rather than the built-in Wilson case.
Look at how the condition plays out in the actual examples. For 23, the smallest witness is n = 14: 14! is congruent to -1 mod 23, and 23 mod 14 equals 9, which is not 1, so the side condition holds and 23 is a Pillai prime. For 29, the smallest witness is n = 18, where 29 mod 18 equals 11, again not 1, so 29 qualifies too. In each case the witness is well below p - 1, and the residue of p modulo n is something other than 1. The Pillai primes begin 23, 29, 59, 61, 67, 71 and 79, and each one earns its place by passing both tests.
Contrast that with 19. It is prime, but no n below 19 satisfies both conditions, so 19 is not a Pillai prime. The absence of a qualifying witness is exactly what the two-part definition is designed to detect. If the side condition were removed, 19 would have the Wilson-theorem witness n = 18 and would wrongly appear on the list. This is why the side condition matters: it keeps the definition from being trivially true for every prime and preserves the distinction between primes that merely satisfy a factorial congruence and those that do so in the specific, restricted way the definition intends.
When you use a Pillai prime calculator, the side condition is the check that separates a real result from a false positive. A page that reports only the factorial congruence would list primes that fail the definition. Checking that p is not congruent to 1 mod n is a small step, but it is the step that gives the term Pillai prime its meaning.
Pillai primes in research
Pillai primes are thin on the ground. The sequence opens 23, 29, 59, 61, 67, 71 and 79 — seven primes before you reach 80, and no others in that stretch. That density is not maintained. Because the definition imposes two conditions at once, a candidate prime must clear both before it qualifies, and most primes fail one or the other. The result is a list that grows slowly and unevenly, which is precisely why a Pillai prime calculator is useful for checking individual candidates rather than trying to survey a range by hand.
The two conditions are worth restating, because they explain the sparseness. A prime p is a Pillai prime when some n satisfies n! congruent to -1 mod p, and p is not congruent to 1 mod n. The first condition alone is a statement about factorials modulo p; the second is a small arithmetic restriction tying p back to the witness n. A prime can satisfy one and miss the other. 19 is prime but is not a Pillai prime, since no n below 19 meets both conditions. Contrast that with 23, where the smallest witness is n = 14: 14! is congruent to -1 mod 23, and 23 mod 14 equals 9, not 1. For 29 the smallest witness is n = 18, and 29 mod 18 equals 11. In each case the residue check is what separates a near miss from a genuine entry.
Computational searching follows directly from that structure. For a given prime p, a search walks n upward, tracking n! modulo p, and tests at each step whether the factorial has reached -1 mod p and whether p mod n differs from 1. The smallest n that passes both tests is the witness. This is a bounded, mechanical procedure — well suited to a calculator that reports the first witness rather than merely a yes or no — but it is also the reason the list stays short: each new candidate demands its own pass through the factorials, and witnesses are not small. Fourteen and eighteen are modest; later entries can require substantially more work before a witness appears.
The connection to factorial number theory is the conceptual heart of the definition. Statements about n! modulo a prime sit at the intersection of factorial growth and modular arithmetic, a territory that also hosts Wilson's theorem and related congruences. Pillai primes mark the primes for which the factorial sequence, read modulo p, lands on -1 at some point under an added non-degeneracy condition. That makes them a natural test case for anyone studying how factorials distribute across residue classes, and a natural entry for anyone learning to compute with them.
For research use, treat the sequence as a reference list and the calculator as the instrument. Verify a suspected member by its smallest witness, confirm the residue condition explicitly, and do not assume that proximity to a known entry implies membership. The gaps between 29 and 59, and the tight cluster from 59 to 79, are a reminder that the sequence rewards direct computation over pattern-guessing.
FAQs
What is a Pillai prime?
A Pillai prime is a prime p that has a witness n such that n! is congruent to -1 mod p, and p is not congruent to 1 mod n. Both conditions must hold at the same n for p to count as a Pillai prime. The definition ties a factorial congruence to a side condition on p and n together.
What is the smallest Pillai prime?
The smallest Pillai prime is 23, with smallest witness n = 14. At n = 14, the factorial 14! is congruent to -1 mod 23, and the side condition holds: 23 is not congruent to 1 mod 14. No smaller prime satisfies both Pillai conditions, which makes 23 the first case.
Is 19 a Pillai prime?
No. Although 19 is prime, no n below 19 meets both of the Pillai conditions. Some n may satisfy one condition, but the definition requires the factorial congruence and the side condition to hold together. Without a witness n that passes both tests, 19 does not qualify as a Pillai prime.
Is 29 a Pillai prime?
Yes. The witness for 29 is n = 18. At that length, 18! is congruent to -1 mod 29, and the side condition holds because 29 mod 18 = 11, which is not 1. Since both Pillai conditions are met at n = 18, 29 is a Pillai prime.
What does the witness n mean?
The witness n is the smallest factorial length whose value hits -1 modulo p while the side condition also holds. In other words, it is the first n at which n! is congruent to -1 mod p and p is not congruent to 1 mod n. The witness identifies where a prime first satisfies both Pillai conditions.
How are Pillai primes found?
Pillai primes are found by computing factorials modulo p one step at a time and testing each n against both conditions. This approach is cheap for small p but gets heavier as p grows, since each new n requires another modular multiplication and another check of the side condition.