Problems > Zeros at the End of N! > Editorial

Zeros at the End of N! — Solution & Editorial

Back to the Problem

Each trailing zero needs a factor 10 = 2·5, and 5s are scarcer: count them with Legendre's formula ∑ ⌊N/5i⌋.

Complexity: O(log5 N)