Trailing Zeroes in a Factorial
Kestrel Analytics sets a weekly puzzle whose answer is always n! -- the number of ways to arrange n distinct items in a row. Printing that answer is hopeless, since 1000! alone runs to 2,568 digits, so the answer key publishes a short checksum instead: how many zeroes the number ends in. A solver who has the real answer on paper can count the zeroes off the end and confirm the match. The key itself has to produce the count without ever building the factorial, because n goes high enough to make that impossible.
Task: Print how many zeroes n! ends in, without building n!.
Input
A single line holding one integer n, with 0 <= n <= 1,000,000.
Output
One line holding a single integer, the number of zeroes at the end of n!. Print 0 when there are none.
Example:
Input:
10
Output:
2
(10! = 3628800, which has 2 trailing zeroes)
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in