In mathematics, Legendre's formula gives the exponent of a prime number $p$ in the prime factorization of $n!$ (n factorial). It is named after the French mathematician Adrien-Marie Legendre.
Statement
For any prime number $p$ and any positive integer $n$, let $ u_p(n!)$ denote the exponent of the largest power of $p$ that divides $n!$ (the p-adic valuation of $n!$). Legendre's formula states:
$$ u_p(n!) = \sum_{i=1}^{\infty} \left\lfloor \frac{n}{p^i} \right\rfloor = \frac{n - s_p(n)}{p - 1} $$
where $\lfloor x \rfloor$ denotes the floor function, and $s_p(n)$ denotes the sum of the digits of $n$ when written in base $p$. The sum is finite because the terms become zero once $p^i > n$.
Explanation
The formula counts the number of integers in ${1, 2, \dots, n}$ divisible by $p$, plus those divisible by $p^2$ (each contributing an additional factor of $p$), plus those divisible by $p^3$, and so on.
- $\left\lfloor \frac{n}{p} \right\rfloor$ counts multiples of $p$.
- $\left\lfloor \frac{n}{p^2} \right\rfloor$ counts multiples of $p^2$, which contribute a second factor of $p$.
- This continues for all powers $p^i \le n$.
Alternative Form
The equivalent form $\frac{n - s_p(n)}{p - 1}$ follows from writing $n$ in base $p$ as $n = a_k p^k + \dots + a_1 p + a_0$ (where $0 \le a_i < p$). The sum of digits is $s_p(n) = \sum a_i$. Substituting into the summation form and simplifying yields the closed-form expression.
Applications
Legendre's formula is fundamental in number theory and combinatorics. Key applications include:
- Determining the number of trailing zeros of $n!$ in base $b$ (by finding the minimum valuation over prime factors of $b$).
- Proving properties of binomial coefficients, such as Kummer's theorem (the exponent of $p$ dividing $\binom{n}{m}$ equals the number of carries when adding $m$ and $n-m$ in base $p$).
- Analyzing the p-adic valuation of factorials in the study of p-adic numbers and the Gamma function.
History
The formula was published by Adrien-Marie Legendre in his work Essai sur la théorie des nombres (1808), though the underlying principle was likely known to earlier mathematicians. It is sometimes referred to as de Polignac's formula after Alphonse de Polignac, who generalized it in 1826.