Factorials and Trailing Zeros — Summary
"How many zeros at the end of 100!?" is a standard placement question testing the highest-power-of-a-prime idea. Trailing zeros come from factors of 10 = 2 × 5, and since 5s are scarcer than 2s, you just count the 5s.
Key formulas
Highest power of a prime p in n! = ⌊n/p⌋ + ⌊n/p²⌋ + ⌊n/p³⌋ + …
Trailing zeros in n! = ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + … (count of 5s).
Example: zeros in 100! = 20 + 4 = 24. ✓
Highest power of 3 in 50! = 16 + 5 + 1 = 22. ✓
Composite factor: power of a composite = limited by its rarest prime. Power of 6 = 2×3 in 20! = min(power of 2, power of 3) = min(18, 8) = 8.
| Quantity | Rule |
|---|---|
| Trailing zeros in n! | Count of 5s: ⌊n/5⌋+⌊n/25⌋+… |
| Power of prime p in n! | ⌊n/p⌋+⌊n/p²⌋+… |
| Power of composite | min over its primes (using each prime's need) |
Exam Tricks & Tips
- 🎯 Zeros = number of 5s, because 2s are always more plentiful than 5s.
- 🎯 Keep dividing by increasing powers (5, 25, 125…) and add the floors.
- 🎯 For power of 4 = 2² in n!, find power of 2 then divide by 2 (floor).
- 🎯 A jump in zeros happens at multiples of 25, 125… (they contribute extra 5s).
- 🎯 25! has ⌊25/5⌋+⌊25/25⌋ = 6 trailing zeros, not 5.
- ❌ Don't count only ⌊n/5⌋ and stop — you must add ⌊n/25⌋, ⌊n/125⌋ for large n.
Expected exam pattern: trailing zeros of a factorial, highest power of a prime dividing n!, or the largest k with p^k | n!. 1 question, ~45 seconds.
Quick recap: Trailing zeros of n! = count of 5s = ⌊n/5⌋+⌊n/25⌋+…; for any prime use the same running-floor sum; for composites take the binding prime.
Factorials and Trailing Zeros — Flashcards
Q1. What causes a trailing zero in a factorial?
A1. A factor of 10 = 2 × 5; the count of 5s is the limiting factor.
Q2. Trailing zeros formula for n!?
A2. ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + …
Q3. Trailing zeros in 100!?
A3. 20 + 4 = 24.
Q4. Trailing zeros in 25!?
A4. 5 + 1 = 6.
Q5. Highest power of a prime p in n!?
A5. ⌊n/p⌋ + ⌊n/p²⌋ + ⌊n/p³⌋ + …
Q6. Highest power of 3 in 50!?
A6. 16 + 5 + 1 = 22.
Q7. Why count 5s and not 2s for zeros?
A7. 2s are always more abundant, so 5s are the bottleneck.
Q8. Highest power of 6 dividing 20!?
A8. min(power of 2 = 18, power of 3 = 8) = 8.
Q9. Trailing zeros in 30!?
A9. ⌊30/5⌋ + ⌊30/25⌋ = 6 + 1 = 7.
Q10. Highest power of 2 in 20!?
A10. 10 + 5 + 2 + 1 = 18.
Q11. How to get the power of 4 = 2² in n!?
A11. Find the power of 2, then take its floor divided by 2.
Q12. Trailing zeros in 10!?
A12. ⌊10/5⌋ = 2.
Factorials and Trailing Zeros
"How many zeros are at the end of 100! ?" is a signature placement question. Nobody computes 100! — the answer comes from counting how many times 5 appears in it, using one clean formula.
What this topic tests: counting the power of a prime in a factorial (Legendre's formula) and using it for trailing zeros and highest-power questions.
The method
Beginner — why 5s decide trailing zeros
A trailing zero is made by a factor of 10 = 2 × 5. In any factorial there are far more 2s than 5s, so the number of trailing zeros equals the number of 5s in the factorisation of n!.
Intermediate — Legendre's formula
The exponent of a prime p in n! is
[n/p] + [n/p²] + [n/p³] + … (each term floored, stop when the term is 0).
For zeros in n!, count 5s: [n/5] + [n/25] + [n/125] + …
Advanced — highest power of a composite
To find the highest power of, say, 12 = 2²·3 that divides n!, count the 2s and 3s separately, then see how many "12"s you can build.
- Count of 2s = [n/2]+[n/4]+…, count of 3s = [n/3]+[n/9]+…
- Each 12 needs two 2s and one 3 → answer = min([2s]/2, [3s]/1).
The scarcer prime (after dividing by how many it needs) limits the answer.
Worked example
Trailing zeros in 100! Count 5s: [100/5] + [100/25] + [100/125] = 20 + 4 + 0 = 24 zeros.
Highest power of 6 in 30! 6 = 2·3. 3s: [30/3]+[30/9]+[30/27] = 10+3+1 = 14. 2s: [30/2]+[30/4]+…= 15+7+3+1 = 26. Each 6 needs one 2 and one 3 → limited by 3s → 14.
Where it appears
TCS NQT advanced quant, Amazon, Microsoft and Goldman Sachs aptitude, and any "number of zeros / highest power of k dividing n!" MCQ.
Speed tricks and shortcuts
- For zeros, only count 5s — keep dividing by 5 and add the quotients: 100→20→4→0 gives 24.
- A jump in zeros happens at multiples of 25, 125 (extra 5s), so 24! and 25! differ by more than one zero at the 25 boundary.
- Mnemonic: "Zeros come from fives; divide-and-add."
- For a prime power p^k as divisor, divide the prime's count by k and floor.
Counting 10s directly, or forgetting the higher terms [n/25], [n/125]. 25 contributes two 5s, 125 contributes three — miss these and your zero count is short.
- ✓- Trailing zeros in n! = count of 5s = [n/5]+[n/25]+[n/125]+…
- ✓- Legendre: exponent of p in n! = Σ [n/p^i].
- ✓- Composite divisor → count each prime, divide by its need, take the minimum.
- ✓- 2s are always plentiful; 5s are the bottleneck for zeros.
- ✓Never expand a factorial. Count the scarce prime with Legendre's divide-and-add, and remember trailing zeros are governed entirely by the number of 5s.
Factorials and Trailing Zeros — Formula Sheet
Key formulas
- Trailing zeros in n! = ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + … (count factors of 5).
- Highest power of prime p in n! = Σ ⌊n/pᵏ⌋ (Legendre's formula).
- n! = n × (n−1)!; 0! = 1! = 1.
- Number of digits ≈ via logarithms; factorial grows super-exponentially.
- Unit digit of n! is 0 for n ≥ 5.
- Zeros come from pairs of 2 and 5; 5s are the limiting factor.
- ✓- Trailing zeros of n! = ⌊n/5⌋+⌊n/25⌋+⌊n/125⌋+…
- ✓- Highest power of p in n! = Σ⌊n/pᵏ⌋ (Legendre).
- ✓- Zeros limited by the count of 5s.
- ✓- 0! = 1! = 1.
Usage: count the 5s (not 2s) to get the trailing zeros of a factorial.
Factorials and Trailing Zeros — Worked Example
Worked Example
Problem: How many trailing zeros are there in 100! (100 factorial)?
Solution: A trailing zero is produced by a factor of 10 = 2 × 5. In any factorial there are far more factors of 2 than of 5, so the number of trailing zeros equals the number of times 5 divides 100!.
Use Legendre's formula — repeatedly divide by powers of 5 and take floors:
- ⌊100 / 5⌋ = 20 (multiples of 5)
- ⌊100 / 25⌋ = 4 (extra 5 from 25, 50, 75, 100)
- ⌊100 / 125⌋ = 0 (125 > 100, stop)
Total factors of 5 = 20 + 4 + 0 = 24.
Since factors of 2 are plentiful, each 5 pairs with a 2 to make a 10, giving 24 trailing zeros.
Answer: 24.
- ✓- Trailing zeros in n! = count of factor 5 (2s are always in surplus).
- ✓- Add ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + … and stop when the term hits 0.
- ✓- Higher powers (25, 125) matter because such numbers contribute more than one 5.