n. How many zeros does the decimal form of n! = 1 · 2 · … · n end with? By convention, 0! = 1.
The factorial itself is enormous for large n, so try to get the answer without computing it, in time logarithmic in n.n=7 → 1
7! = 5040, which ends in a single zero.
n=26 → 6
Each zero comes from a pair of factors 2 and 5. Numbers up to 26 contribute six 5s: one each from 5, 10, 15, 20 and two from 25. There are more 2s than that, so there are 6 zeros.
n=1 → 0
n ≤ 10⁹n=7
1
Run checks the first 3 tests in your browser. Submit checks all 74 tests on the server, hidden ones included.