Module 3.6 · Number Theory
Factorials and Legendre's formula
You already know how to count trailing zeros of by counting factors of . Legendre's formula is the general version: it gives the exact power of any prime in . With it you can find trailing zeros in any base, the largest power of dividing , and the power of a prime dividing a binomial coefficient. That last one leads to a beautiful fact about which entries of Pascal's triangle are odd.
Legendre's formula
Among , exactly are multiples of , and each contributes at least one factor of to . Exactly are multiples of , and each contributes a second factor. Continue with Each number is counted once for every factor of it has.
Legendre's formula
The exponent of the prime in is
where is the sum of the digits of in base .
The digit-sum form is a great shortcut for : . For instance, has eight s, so .
Trailing zeros in any base
ends in zeros in base when divides but does not. Factor into primes; for each prime power in , the number of copies available is . The answer is the smallest of these. In base the bottleneck is always , but in other bases you must check each prime.
Binomial coefficients
Since , you get . Using the digit-sum form, this simplifies to
which equals the number of carries when you add and in base (Kummer's theorem). In particular, is odd exactly when adding and in binary has no carries, meaning every in the binary form of sits where also has a . So if has ones in binary, exactly entries in row of Pascal's triangle are odd.
Worked example: A prime in a factorial
What is the largest power of that divides ?
So divides but does not.
Worked example: Trailing zeros in base 12
How many zeros does end in when written in base ?
. Factors of : , enough for copies of . Factors of : . The bottleneck is , so ends in zeros in base .
Worked example: A power of 2 in a binomial coefficient
What is the largest power of dividing ?
By Legendre, and . So , and the answer is .
With carries: has three s, and adding in binary carries exactly once for each of them. Three carries again gives .
Worked example: Odd entries in a row of Pascal's triangle
For how many with is odd?
has three s. is odd exactly when the s of are among those three positions, so there are such .
Common mistake
For a base like , don't just compare and . You need two s for every , so divide by (rounding down) before comparing. Also, don't stop Legendre's sum early: terms keep contributing until .
Practice
How many zeros are at the end of ?
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
What is the largest integer such that divides ?
How many zeros does end in when written in base ?
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
What is the largest integer such that divides ?
What is the smallest positive integer such that no factorial ends in exactly zeros?
What is the exponent of in the prime factorization of ?
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
What is the smallest positive integer such that divides ?
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
For how many integers with is odd, and for how many with is odd? Give the sum of the two counts.
Real contest practice
- 2015 AMC 10B, Problem 23: comparing the trailing zeros of and .
- 2017 AMC 12B, Problem 16: the probability that a random divisor of is odd, using the power of in .