# 100 Factorial

Source: https://www.techinterview.org/post/491337394/100-factorial/
Updated: 2026-07-05 · techinterview.org

how many **trailing** zeroes are there in 100! (100 factorial)?

### Solution

One per factor of 10, and one per factor of 5 (there are more than enough 2’s to pair with the 5’s), plus one per factor of ten squared (one occurrence) and one per factor of 5 squared (three occurrences).

So if I’m counting correctly, that’d be 10 + 10 + 1 + 3== 24 zeroes.

Assuming the question meant *trailing* zeroes. It’d be much harder to also count the intermingled zero digits in the entire expansion.

## 2026 Update: Trailing Zeros in n! — And Why It Matters

How many trailing zeros does 100! have? The naive approach — compute 100! then count zeros — overflows. The clever approach: count factors of 10 = min(factors of 2, factors of 5) in 100!. Since factors of 2 always exceed factors of 5, just count factors of 5.


```
def trailing_zeros_factorial(n: int) -> int:
    """
    Count trailing zeros in n!
    Each trailing zero requires one factor of 10 = 2 × 5.
    Factors of 2 always outnumber factors of 5, so count 5s.
    """
    count = 0
    power = 5
    while power <= n:
        count += n // power
        power *= 5
    return count


# Example: 100! has 24 trailing zeros
print(trailing_zeros_factorial(100))  # 24


def trailing_zeros_base_b(n: int, b: int) -> int:
    """Count trailing zeros in n! when written in base b."""
    from sympy import factorint
    prime_factors = factorint(b)
    result = float('inf')
    for p, exp in prime_factors.items():
        # Count factors of prime p in n!
        p_count = 0
        power = p
        while power <= n:
            p_count += n // power
            power *= p
        result = min(result, p_count // exp)
    return result

# Base 12: 12 = 2^2 * 3, so need pairs of (2^2, 3)
print(trailing_zeros_base_b(100, 12))  # limited by 3s: 100//3+100//9+...=48, //2=24
```

**Why interviewers ask this:** Tests mathematical thinking over brute-force. The key insight (count prime factors of the smaller prime) generalizes to: number of times k divides n!, Legendre's formula, and combinatorics problems about divisibility. Appears at Jane Street, Citadel, Google, and quantitative trading firms.
