Trailing Zeros in Factorial Using the Division Method

Trailing Zeros in Factorial means the zeroes at the end of the decimal form of n!. The count depends on the number of pairs of factors 2 and 5 in the factorial. Since factors of 2 are more frequent, the answer is found by counting factors of 5 using successive powers of 5.

On this page

What Are Trailing Zeros in a Factorial?

The number of trailing zeros in n! is the exponent of 10 in its prime factorisation. It is calculated by counting the factors of 5 in n!, because factors of 2 occur more frequently.

Each trailing zero requires one factor pair of 2 × 5 = 10. For a positive integer n, the count is obtained by adding the multiples of 5, 25, 125 and higher powers of 5 that are not greater than n. For example, 25! has 5 + 1 = 6 trailing zeros.

Trailing Zeros in Factorial Formula & Tricks

Important Formulas

Trailing zero formula
Number of trailing zeros in n! = ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + ...

Continue adding terms while 5^k ≤ n. Each term counts the contribution of factors of 5 from multiples of that power.

Prime-factor form
Number of trailing zeros in n! = min(v₂(n!), v₅(n!)) = v₅(n!)

A zero requires one factor 2 and one factor 5. Since v₂(n!) is greater than v₅(n!), the number of zeros equals the total exponent of 5.

Quick Tricks

Count multiples of 5, 25 and higher powers

Count every multiple of 5 once, every multiple of 25 an additional time, every multiple of 125 another time, and so on.

Example: For 100!, the count is ⌊100/5⌋ + ⌊100/25⌋ = 20 + 4 = 24.
Do not stop at the first division by 5

Numbers such as 25, 125 and 625 contain more than one factor of 5. Their extra factors must be counted through successive powers of 5.

Example: For 125!, the count is 25 + 5 + 1 = 31, not just 25.

Trailing Zeros in Factorial Concepts

Why factors of 5 determine the zeros

A trailing zero is produced by a factor of 10, and each factor of 10 is formed from one factor of 2 and one factor of 5.

In n!, factors of 2 are more numerous than factors of 5 because every second number contributes a factor of 2, while only every fifth number contributes a factor of 5. Therefore, the smaller exponent, v₅(n!), determines the number of trailing zeros.

Example: In 10!, there are eight factors of 2 and two factors of 5, so 10! ends in two zeros.

Legendre method for n!

Use the sum of floor divisions by successive powers of 5 to find the number of trailing zeros in n!.

The required calculation is ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + ... . Stop when the next power of 5 is greater than n. The first term counts multiples of 5, while later terms count extra factors from multiples of 25, 125 and higher powers.

Example: For 50!, the count is ⌊50/5⌋ + ⌊50/25⌋ = 10 + 2 = 12.

Extra factors from powers of 5

A multiple of 25 contributes two factors of 5, a multiple of 125 contributes three, and a multiple of 625 contributes four.

The first division by 5 counts such numbers once. Dividing by 25, 125 and higher powers counts their additional factors of 5. This prevents undercounting in factorials containing powers of 5.

Example: In 125!, the multiples of 5 contribute 25 factors, multiples of 25 contribute 5 extra factors, and 125 contributes 1 more factor. Thus, the total is 31.

Finding the smallest n for a required number of zeros

To find the smallest n for which n! has at least k trailing zeros, evaluate the formula for increasing candidates or use binary search.

The function Z(n) = ⌊n/5⌋ + ⌊n/25⌋ + ... is non-decreasing. For example, 24! has 4 zeros, while 25! has 6 zeros, so 25 is the smallest n for at least 6 trailing zeros.

Example: Z(24) = 4 and Z(25) = 5 + 1 = 6. Therefore, the smallest n such that n! has at least 6 zeros is 25.

Trailing Zeros in Factorial Video Lessons

Watch short topic-wise lessons for quick revision.

14 Lessons
Lesson 1 of 14 Quick Revision

Factorials: Trailing Zeros and Prime Powers

Learn how to find trailing zeros in factorials and determine the highest power of a prime that divides a factorial using standard number system methods.

Continue with more lessons and practice in PrepShots.Watch More in App - Start ₹1 Trial →
More Trailing Zeros in Factorial Lessons Scroll to explore →

Practice Trailing Zeros in Factorial Questions

Practise published questions related to this topic.

Trailing Zeros in Factorial Quick Quiz

Attempt 5 questions and check your score instantly.

Quick Revision Notes

Trailing Zeros in Factorial: Quick Revision

Use these rules to calculate trailing zeros in n! quickly and accurately.

  • A trailing zero is formed by one pair of factors 2 and 5.
  • For n!, factors of 2 exceed factors of 5, so count the factors of 5.
  • Formula: Z(n!) = ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + ... .
  • Continue until the power of 5 becomes greater than n.
  • Multiples of 25, 125 and higher powers contribute extra factors of 5.
  • For 100!, Z(100!) = 20 + 4 = 24.
  • For 125!, Z(125!) = 25 + 5 + 1 = 31.

Trailing Zeros in Factorial FAQs

What is the formula for trailing zeros in n!?

The formula is Z(n!) = ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + ... . Add terms until 5^k exceeds n.

How many trailing zeros does 100! have?

Z(100!) = ⌊100/5⌋ + ⌊100/25⌋ = 20 + 4 = 24. Therefore, 100! has 24 trailing zeros.

How many trailing zeros does 50! have?

Z(50!) = ⌊50/5⌋ + ⌊50/25⌋ = 10 + 2 = 12. Hence, 50! has 12 trailing zeros.

Why are multiples of 25 counted twice?

Every multiple of 25 contains at least two factors of 5. The division by 5 counts one factor, and the division by 25 counts its additional factor.

How many trailing zeros are in 125!?

Z(125!) = ⌊125/5⌋ + ⌊125/25⌋ + ⌊125/125⌋ = 25 + 5 + 1 = 31.

What is the smallest n for which n! has at least 6 trailing zeros?

The smallest value is n = 25. Since Z(24!) = 4 and Z(25!) = 5 + 1 = 6, 25! is the first factorial with at least 6 trailing zeros.

Continue learning Trailing Zeros in Factorial on PrepShots

Continue on PrepShots