30 lines
552 B
C++
30 lines
552 B
C++
#include <iostream>
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
int n;
|
|
std::cin >> n;
|
|
|
|
if (n < 0)
|
|
{
|
|
std::cout << -1 << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
int x = 0;
|
|
|
|
// Observed pattern where the number of trailing zeroes increases by
|
|
// one for every additional factor of 5.
|
|
// e.g. 0! to 4! has 0, 5! to 9! has 1, 10! to 14! has 2, and so on.
|
|
// Turns out you need to consider additional powers of 5 (25, 125, etc).
|
|
// This was not obvious at first since 25! overflowed.
|
|
for (int i = 5; n / i >= 1; i *= 5)
|
|
{
|
|
x += n / i;
|
|
}
|
|
|
|
std::cout << x << std::endl;
|
|
return 0;
|
|
}
|