Factorial Prime Calculator

Factorials

11! + 1 = 39,916,801prime
11! - 1 = 39,916,799composite (smallest factor 13)
n! itself39,916,800
verdictfactorial prime found: 11! + 1
How this was calculated
  1. A factorial prime is a prime of the form n! + 1 or n! - 1; this calculator tests both neighbours of n!.
  2. Here 11! = 39,916,800, so the two candidates are 39,916,799 and 39,916,801.
  3. Primality is decided by a deterministic Miller-Rabin test with bases 2 to 37, which is exact for every number below 3.8 x 10^18, and trial division up to 1,000,000 exposes a small factor when there is one.
  4. For reference, up to n = 20 the only n! + 1 primes sit at n = 1, 2, 3, 11 and the only n! - 1 primes at n = 3, 4, 6, 7, 12, 14 - most factorials have no prime neighbour at all.

A factorial prime is a prime number sitting immediately next to a factorial: one of the form n! + 1 or n! - 1. The two neighbours behave very differently. 11! + 1 = 39,916,801 is prime, while 11! - 1 = 39,916,799 falls apart with smallest factor 13. At n = 13 neither neighbour is prime at all.

These numbers are not a curiosity for their own sake. Euclid's proof that there are infinitely many primes runs straight through n! + 1: none of the primes up to n can divide it, so every prime factor it has is a new prime. Factorial primes are the rare case where that guaranteed-new factor turns out to be the number itself.

This calculator tests both neighbours of n! for n up to 20. Primality is decided by a deterministic Miller-Rabin test with bases 2 to 37, which is provably exact for every number below 3.8 x 10^18 - and 20! + 1 is about 2.4 x 10^18, inside the proven range. When a neighbour is composite, trial division up to 1,000,000 reports its smallest factor when one exists.

Worked examples

Neighbours of 11!

(11)

11! + 1 = 39,916,801prime
11! - 1 = 39,916,799composite (smallest factor 13)
n! itself39,916,800
verdictfactorial prime found: 11! + 1

Neighbours of 12!

(12)

12! + 1 = 479,001,601composite (smallest factor 13)
12! - 1 = 479,001,599prime
n! itself479,001,600
verdictfactorial prime found: 12! - 1

Neighbours of 13!

(13)

13! + 1 = 6,227,020,801composite (smallest factor 83)
13! - 1 = 6,227,020,799composite (smallest factor 1,733)
n! itself6,227,020,800
verdictno factorial prime at this n

What a factorial prime is

Start with the factorial n! = 1 x 2 x ... x n and look at the two integers flanking it. A prime of the form n! + 1 is sometimes called a plus-factorial prime and one of the form n! - 1 a minus-factorial prime; together they are the factorial primes. The calculator tests both sides at once, because knowing one side tells you nothing about the other.

There is a structural reason the two sides differ. Every prime p up to n divides n! itself, so it can divide neither neighbour - both n! + 1 and n! - 1 are automatically free of small factors up to n. But n! - 1 has an extra trick available to its enemies: primes p where p is one more than a divisor pattern of the factorial can divide it, which is why 11! - 1 = 39,916,799 is divisible by 13, the very next prime after 11. The same fate hits 12! + 1 = 479,001,601, also divisible by 13.

  • Plus side: primes of the form n! + 1
  • Minus side: primes of the form n! - 1
  • No prime up to n can divide either neighbour
  • But the next prime often can: 13 divides both 11! - 1 and 12! + 1

The results up to n = 20

Prime neighbours are scarce. On the plus side, up to n = 20 the only n! + 1 primes sit at n = 1, 2, 3 and 11. On the minus side the only n! - 1 primes sit at n = 3, 4, 6, 7, 12 and 14. Most factorials - including 13!, 15!, 16! and 20! - have no prime neighbour at all, and the calculator shows the smallest factor of each composite neighbour so the failure is concrete rather than a bare verdict.

The worked examples on this page show the three flavours of outcome. At n = 11 the plus side wins: 39,916,801 is prime. At n = 12 the minus side wins: 479,001,599 is prime while the plus side is divisible by 13. At n = 13 both sides lose: 13! + 1 = 6,227,020,801 has smallest factor 83 and 13! - 1 = 6,227,020,799 has smallest factor 1,733.

Whether infinitely many factorial primes exist is unknown, on either side. Heuristics modelled on the prime number theorem predict the count grows very slowly, roughly like a constant times log log of the bound, which matches the observed trickle: searches have pushed to factorials with hundreds of thousands of digits and still find them only occasionally.

  • n! + 1 prime at n = 1, 2, 3, 11 (up to 20)
  • n! - 1 prime at n = 3, 4, 6, 7, 12, 14 (up to 20)
  • n = 11: plus side prime; n = 12: minus side prime; n = 13: neither
  • Infinitely many? An open problem on both sides

How the primality is proven

Trial division is hopeless for numbers like 20! + 1, which has 19 digits. The calculator instead runs the Miller-Rabin strong probable prime test with the bases 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 and 37. For a general number that test is probabilistic, but for numbers below 3,825,123,056,546,413,051 it has been verified exhaustively that passing those twelve bases is equivalent to being prime - the test is deterministic in this range, a proof rather than a bet.

Since 20! + 1 is about 2.43 x 10^18, comfortably below that bound, every verdict this calculator gives for n up to 20 is exact. When the verdict is composite, a separate trial division up to 1,000,000 runs to exhibit a factor: it finds 13 for 11! - 1, 83 for 13! + 1 and 1,733 for 13! - 1. Some composites have no factor that small - 20! - 1, for instance, has smallest factor 124,769, which the search does find, while a composite whose factors all exceed a million is honestly reported as composite with no small factor.

  • Miller-Rabin bases 2 to 37: deterministic below 3.8 x 10^18
  • 20! + 1 is about 2.43 x 10^18, inside the proven range
  • Trial division to 1,000,000 exhibits small factors: 13, 83, 1,733
  • A composite with no factor under a million is reported as such

Euclid's proof connection

Around 300 BC Euclid proved there are infinitely many primes by considering the number formed by multiplying all known primes and adding 1. The factorial version is the same idea with the product 1 x 2 x ... x n: every prime up to n divides n!, so none of them divides n! + 1, and therefore n! + 1 must have a prime factor larger than n. There is always a bigger prime.

A factorial prime is the glamorous special case where n! + 1 needs no factoring at all because it is itself prime. Euclid's argument works either way, but the primes it guarantees are usually hiding inside a composite n! + 1 - at n = 13, for example, the new prime guaranteed by the proof is 83, sitting inside 6,227,020,801. The calculator's smallest-factor report shows exactly where Euclid's new prime went.

  • Euclid: n! + 1 has a prime factor above n, always
  • A factorial prime is the case where n! + 1 is that prime itself
  • At n = 13 the guaranteed new prime is 83, a factor of 13! + 1
  • The proof needs the factor, not the primality of the whole

Searching beyond n = 20

This calculator stops at n = 20 because that is where its deterministic Miller-Rabin proof range ends, but the search for factorial primes continues far beyond. Dedicated hunts have tested n into the hundreds of thousands, where n! has hundreds of thousands of digits and a single primality proof is a serious computation. The known plus-side and minus-side lists grow by isolated entries separated by enormous gaps, exactly as the heuristics predict.

The heuristics deserve a word. A random integer near n! has probability about 1 / ln(n!) of being prime, but n! + 1 and n! - 1 are not random - they are guaranteed free of prime factors up to n, which multiplies their chance of primality by roughly e^gamma x ln n (a Mertens-theorem factor). Even with that boost, the expected count of factorial primes up to x grows like a constant times log log x - agonisingly slowly. Doubling the search range adds, in expectation, a small fraction of one new prime.

That scarcity is precisely the appeal. Each new factorial prime is a small event in the factoring community, announced and independently verified, and the two-sided nature of the search means every n offers two lottery tickets. The calculator's range, n up to 20, covers the historical core of the subject - everything Euclid through the early computer era could see - and its smallest-factor reports show the mechanism that kills most candidates: a prime just above n, like 13 at n = 11 and 12, reaching in to divide a neighbour.

  • Searches run to n in the hundreds of thousands
  • Heuristic count grows like a constant times log log x
  • Neighbours are pre-sieved: no prime factor up to n
  • New finds are rare, announced events

FAQs

What is a factorial prime?

A prime of the form n! + 1 or n! - 1. For example 11! + 1 = 39,916,801 is prime.

Is 12! - 1 prime?

Yes - 479,001,599 is prime, while 12! + 1 = 479,001,601 is composite with smallest factor 13.

Does 13! have a prime neighbour?

No. 13! + 1 has smallest factor 83 and 13! - 1 has smallest factor 1,733, so neither side is prime.

How many factorial primes are there up to n = 20?

On the plus side n = 1, 2, 3, 11; on the minus side n = 3, 4, 6, 7, 12, 14. Most factorials have no prime neighbour.

How is primality tested for numbers this large?

By deterministic Miller-Rabin with bases 2 to 37, which is exact for every number below 3.8 x 10^18 - a range that covers all factorials up to 20!.

Why do n! + 1 and n! - 1 matter?

Euclid's infinitude proof runs through n! + 1: no prime up to n can divide it, so any prime factor it has is a new, larger prime.

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.