Find n!. The number of zeros.
To n! do qualitative factor decomposition n!=2x*3y*5z* ...
Obviously the number of 0 equals min (x,z), and Min (x,z) ==z
Prove:
For factorial, that is, 1*2*3*...*n [n/k] represents the number of 1~n that can be divisible by k so obviously [N/2] > [N/5] (on the left is 2 increase 1, on the right is 5 increase 1) [n/2^2] > [n/5^2] (on the left is every 4 Increase by 1, on the right is 25 increase 1) ... [N/2^p] > [N/5^p] (on the left is every 2^p increase 1, the right is every 5^p increase 1) with the rise of power p, the probability of 2^p will be far greater than the probability of 5^p. So the left side of the addition and must be greater than the right side of the sums, that is, n! quality factor decomposition, 2 power must be greater than the power of 5
PS. Proof from the Internet
1 Public classSolution {2 Public intTrailingzeroes (intN) {3 intCNT = 0;4 while(N > 0) {5CNT + = N/5;6N/= 5;7 }8 9 returnCNT;Ten } One}
Leetcode-factorial Trailing Zeroes