Zeros at the End of N! — Solution & Editorial
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)
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)