The -adic valuation is the exponent of prime in’s prime factorization — how many times divides . This lesson is about computing , which shows up constantly in “how many trailing zeros” and “highest power of a prime dividing this factorial” problems.
Legendre’s formula
The sum is finite in practice — once , that term (and every later one) is zero, so you just stop once the floor becomes 0.
Trailing zeros
A trailing zero in comes from a factor of 10, i.e. a pair of factors 2 and 5. Since factors of 2 are far more abundant than factors of 5 in any factorial, the number of trailing zeros is limited entirely by — you only ever need to apply Legendre’s formula with.
Worked example
Problem: How many trailing zeros does have?
Solution: Compute :
So ends in 24 zeros.
Practice problems
1.Find .
2.How many trailing zeros does have?
3.Find the largest power of 3 dividing .
4.Why does end in exactly 24 zeros rather than needing to check factors of 2 as well?