Skip to content

Factorials and Trailing Zeros

6 lessons · 20 questions · 16 PYQs · ~55 s per question

The idea

N!N! contains every integer up to NN, so the exponent of a prime pp in it is the number of multiples of pp, plus the multiples of p2p^2 (which carry a second factor), and so on. Trailing zeros are exponents of 10=2×510=2\times5, and 55 is always the scarcer prime.

Textbook vs exam method

Exam method

  1. Indore 2019 Q22. v7(50!)=7+1=8v_7(50!)=7+1=8, v3(50!)=22v_3(50!)=22: n=8n=8.Indore 2019
  2. Zeros of 146!146! limited by v3v_3 when the base is 66: 48+16+5+1=7048+16+5+1=70.
  3. 'How many NN have N!N! with exactly 2323 zeros': 99!→2299!\to22, 100!→24100!\to24: none.
  4. 100!+200!=100!(1+101⋯200)100!+200!=100!(1+101\cdots200): the bracket ends in 11, zeros =24=24.
  5. 1001=7⋅11⋅131001=7\cdot11\cdot13 in 1001!1001!: v13=77+5=82v_{13}=77+5=82 is the minimum.

Worked examples

Example 1Sitter

Zeros of 125!125!

Example 2Easy

Highest power of 24=23⋅324=2^3\cdot3 in 108!108!

Example 3Easy

Zeros of (34!)31!(34!)^{31!}

Example 4Typical

Smallest NN with N!N! having at least 3131 zeros

Example 5Typical

Zeros of 5×10×15×⋯×1005\times10\times15\times\dots\times100

Traps

  • Only ⌊N/5⌋\lfloor N/5\rfloor; wrong prime chosen for composite bases; impossible zero counts; zero counts added for sums.

Formulas

Legendre's formula

vp(N!)=⌊Np⌋+⌊Np2⌋+⌊Np3⌋+…v_p(N!)=\left\lfloor\frac Np\right\rfloor+\left\lfloor\frac N{p^{2}}\right\rfloor+\left\lfloor\frac N{p^{3}}\right\rfloor+\dots

Divide by p, then p^2, p^3, ... and add the quotients (floor each time).
Trailing zeros of a factorial

Z(N!)=v5(N!)(factors of 2 are never scarce)Z(N!)=v_5(N!)\quad(\text{factors of 2 are never scarce})

Indore style: zeros of 100! = 20 + 4 = 24.
Highest power of a composite in a factorial

m=∏piai: max⁡{n:mn∣N!}=min⁡i⌊vpi(N!)ai⌋m=\prod p_i^{a_i}:\ \max\{n: m^{n}\mid N!\}=\min_i\left\lfloor\frac{v_{p_i}(N!)}{a_i}\right\rfloor

Indore 2019 Q22: 21 = 3 x 7, v_7(50!) = 8 < v_3(50!) = 22, so 21^8 is the highest power; divide by the exponent inside m when m has a prime power (12 = 2^2 x 3).
Inverse trailing-zero problems

Z(N!)≈N4; each value is taken by exactly 5 consecutive N or by none (skips at multiples of 25)Z(N!)\approx\frac N4;\ \text{each value is taken by exactly 5 consecutive }N\text{ or by none (skips at multiples of 25)}

A zero count is skipped when N passes a multiple of 25 (23 zeros never occur: 99! has 22, 100! has 24); 'how many N' is 5 or 0.
Factorial sums and differences

vp(N!−M!)=vp(M!) (M<N, p∣some factor in M+1..N);N!+(N+1)!=N! (N+2)v_p(N!-M!)=v_p(M!)\ (M<N,\ p\mid\text{some factor in }M+1..N);\quad N!+(N+1)!=N!\,(N+2)

Factor out the smaller factorial; the bracket is co-prime to the prime in question (500! - 200!: v_7 = v_7(200!) = 32).
Zeros of general products

Z(∏ki)=min⁡(∑v2(ki), ∑v5(ki));c×2c×⋯×nc=cn n!Z\left(\prod k_i\right)=\min\left(\sum v_2(k_i),\ \sum v_5(k_i)\right);\quad c\times2c\times\dots\times nc=c^{n}\,n!

Count 2s and 5s separately and take the smaller; 5 x 10 x ... x 5n = 5^n n! is limited by the 2s.

In the exam

Shortcuts
  • Zeros of N!N!: keep dividing by 55 and add the quotients (1000→200+40+8+1=2491000\to200+40+8+1=249).
  • For mn∣N!m^{n}\mid N! find the prime of mm that runs out first; it is almost always the largest prime, unless a small prime appears with a high exponent in mm.
  • Estimate N≈4kN\approx4k for 'N!N! has kk zeros', then step by 55 and check.
  • For N!±M!N!\pm M! pull out M!M!; the bracket decides nothing about the small primes.
  • For products like 1122…nn1^{1}2^{2}\dots n^{n} the exponent of 55 is ∑k v5(k)\sum k\,v_5(k) over multiples of 55.
~55 s per question at exam speed
When to skip: Never - Legendre sums are mechanical. Only an 'exponent of a prime in a difference of huge factorials' item needs the factoring insight; if it is not seen in 30 s, move on.

Before this

What the exams ask here

  • max n with p^n | N!
  • zeros at end of N!
  • 21^n divides 50! (Indore 2019 Q22); highest power of 24 in 108!
  • how many N have N! ending in exactly k zeros; smallest N with k zeros
  • zeros at the end of 5 x 10 x 15 ... / 1^1 2^2 ... n^n / 30 x 60 x ... x 30n
Next sub-topicDigits and Number Forms

Practise this free. Every mistake is saved and comes back until you fix it.

Start free