Kempner Function Calculator
Number Theory
- The Kempner function S(n) is the smallest k such that n divides k! - the first factorial that n fits into exactly.
- Factorising 12 = 2^2 x 3, each prime power p^a demands enough factors of p in the factorial; Legendre's formula counts them, and the binding prime power here is 2^2.
- The smallest factorial divisible by 12 is 4!, so S(12) = 4 - and indeed 4! mod 12 = 0 while (4 - 1)! is not divisible by 12.
- For prime n the Kempner value is n itself - a prime first appears as a factor only in n! - while highly composite n can have strikingly small values, like S(720) = 6 because 720 = 6!.
The Kempner function S(n) answers a disarmingly simple question: what is the smallest factorial that n divides? For 12 the answer is S(12) = 4, because 4! = 24 is divisible by 12 while 3! = 6 is not. For 720 the answer is a satisfying S(720) = 6, because 720 is 6! itself.
This Kempner function calculator finds S(n) the way number theorists do - prime power by prime power. Each prime power p^a in the factorisation of n demands a certain number of factors of p inside the factorial, counted by Legendre's formula, and S(n) is the maximum of those demands. The page shows the factorisation, the binding prime power, and the factorial check S(n)! mod n = 0.
The function's personality is in its contrasts. For a prime p, S(p) = p - the prime cannot appear as a factor until its own factorial. For a highly composite number the value can be startlingly small: S(720) = 6, S(12) = 4, S(6) = 3. The same function that is maximally stubborn at primes collapses at factorials themselves.
Worked examples
S(12)
(12)
| Kempner function S(12) | 4 |
| prime factorisation of n | 2^2 x 3 |
| binding prime power | 2^2 = 4 |
| factorial check: 4! mod 12 | 0 |
S(100)
(100)
| Kempner function S(100) | 10 |
| prime factorisation of n | 2^2 x 5^2 |
| binding prime power | 5^2 = 25 |
| factorial check: 10! mod 100 | 0 |
S(720)
(720)
| Kempner function S(720) | 6 |
| prime factorisation of n | 2^4 x 3^2 x 5 |
| binding prime power | 2^4 = 16 |
| factorial check: 6! mod 720 | 0 |
The first factorial that fits
Read the definition literally: S(n) is the least k with n | k!. Small cases build intuition fast. S(6) = 3 because 3! = 6. S(10) = 5 because 5! = 120 is the first factorial containing both a factor 2 and a factor 5. S(12) = 4 because 4! = 24 supplies the needed 2^2 x 3 while 3! = 6 lacks a factor of 2.
The calculator verifies its answer in the most direct way possible: it reports S(n)! mod n = 0 as a displayed check. The minimality half - that (S(n) - 1)! fails - is guaranteed by the prime-power computation described below, not by testing factorials one by one.
- S(12) = 4, S(6) = 3, S(10) = 5
- S(720) = 6 because 720 = 6!
- Check displayed: S(n)! mod n = 0
Prime powers and Legendre's formula
A factorial k! contains the prime p with multiplicity floor(k/p) + floor(k/p^2) + ... - Legendre's formula. For n to divide k!, every prime power p^a in n's factorisation needs the multiplicity of p in k! to reach at least a. Each prime power therefore sets its own threshold k, and S(n) is the largest threshold among them - the binding prime power.
For 100 = 2^2 x 5^2 the binding power is 5^2 = 25: factors of 5 accumulate slowly in factorials, and 25 first divides into 10! (which contains 5s from 5 and 10). Hence S(100) = 10, set entirely by the 5^2 term even though the 2^2 term is satisfied far earlier. The calculator names the binding prime power for exactly this reason.
- Legendre: multiplicity of p in k! is a sum of floors
- Each prime power sets a threshold; S(n) is the maximum
- For 100 the binding power is 5^2 = 25, giving S(100) = 10
Primes vs composites
At a prime the function is trivial and extreme: S(p) = p, because no factorial before p! contains p as a factor at all. This makes primes the most expensive inputs of their size - S(97) dwarfs S(100) = 10 despite 97 being the smaller number. Size alone says little about the Kempner value; factorisation says everything.
At the other extreme sit the factorials themselves and their neighbours: S(720) = 6 because 720 = 6!, and highly composite numbers generally inherit small values from the factorials they divide. The function thus measures something like factorial complexity - how deep into the factorial sequence a number first fits.
- S(p) = p for every prime
- S(100) = 10 despite 100 > 97 - factorisation rules
- Factorials themselves have minimal values
Kempner vs the Smarandache function
The same function was independently introduced by A. J. Kempner in 1918 and much later popularised under the name Smarandache function. The mathematics is identical - smallest k with n | k! - and the double naming is a standard cautionary tale in attribution. This page uses Kempner's name, the earlier one.
Whichever name is used, the computational content is the prime-power method: factorise, apply Legendre's formula per prime power, take the maximum. Any implementation that searches factorials directly will be hopelessly slow at primes, which is the practical reason the theory matters to the calculator.
- Same function, two names - Kempner (1918) has priority
- Also called the Smarandache function
- Prime-power method, never a factorial search
How the calculator decides
For each prime power p^a dividing n, a short binary search over k finds the least factorial whose p-multiplicity reaches a, using Legendre's formula as the test. The maximum over the prime powers is S(n). Every step is exact integer arithmetic, and the displayed factorial check confirms the result independently.
The binding-prime-power output is the diagnostic to read. When it is a high power of a large prime, S(n) is large for a transparent reason; when n is a factorial, the binding power is small and spread out. Two numbers with the same S(n) can earn it in completely different ways, and the page shows which way yours did.
- Binary search per prime power, Legendre as the test
- Maximum of thresholds is the answer
- Binding prime power explains the result
Worked values to remember
A pocket table anchors the function: S(6) = 3, S(10) = 5, S(12) = 4, S(100) = 10, S(720) = 6. Notice the non-monotonicity - S(12) < S(10) < S(100), but S(720) undercuts them all. Any intuition that bigger inputs give bigger values dies on this table, which is precisely what makes the function interesting.
The calculator reproduces each of these from the factorisation up, so the table doubles as a test suite. If a Kempner implementation cannot explain why 720 is cheaper than 100, it is not computing the same function.
- S(6) = 3, S(10) = 5, S(12) = 4, S(100) = 10, S(720) = 6
- Not monotone: 720 is cheaper than 100
- The pocket table doubles as a test suite
The Kempner table and its spikes
Read across a range of n and the Kempner function looks like a skyline: low rooftops at factorials and smooth numbers, sudden towers at primes. Between the pocket values - S(6) = 3, S(10) = 5, S(12) = 4, S(100) = 10, S(720) = 6 - any prime input spikes to its own height, since S(p) = p. The function is thus a rough primality shadow: large Kempner values relative to size are a prime's signature, though the calculator computes the value, not a primality verdict.
That skyline is why the function appears in computational practice as a stress test: an implementation must handle the spikes (binary search per prime power) and the rooftops (Legendre thresholds) with the same code. This page's method - factorise, threshold each prime power, take the maximum - is indifferent to which regime n falls in.
- Skyline profile: low at factorials, spiking at primes
- S(p) = p makes primes the towers
- One method handles both regimes
Using the calculator
Enter n and read three things: S(n) itself, the factorisation with its binding prime power, and the factorial check. For a prime input the answer will be n itself - a feature, not a malfunction. For composite inputs the binding power tells you which part of n is expensive.
The function rewards experimentation with factorials and primorial-like inputs: try 720, then 721 (which is 7 x 103, and pays for the prime 103), and the contrast teaches the definition faster than any paragraph.
- Read S(n), the binding power, and the check together
- Prime inputs return themselves
- Contrast 720 with its neighbours
FAQs
What is the Kempner function?
S(n) is the smallest k such that n divides k! - the first factorial into which n fits exactly.
What is S(12)?
S(12) = 4, since 4! = 24 is divisible by 12 and 3! = 6 is not.
What is S(720)?
S(720) = 6, because 720 = 6! itself.
What is S(100)?
S(100) = 10, set by the binding prime power 5^2 = 25, which first fits into 10!.
What is S(p) for a prime p?
S(p) = p - a prime first appears as a factor in its own factorial.
How is S(n) computed?
Prime power by prime power: Legendre's formula counts the factors of p in k!, each prime power p^a sets a threshold, and S(n) is the largest threshold.