Design an algorithm to figure out how many trailing zeros n factorial has.

Example 1:

Input: 3 Output: 0 Explanation: 3! = 6. There are no zeros in the mantissa. Example 2:

Input: 5 Output: 1 Explanation: 5! = 120, with one zero in the mantissa. Note: The time complexity of your algorithm should be O(log n).

In fact, n! In, all the zeros are contributed by multiples of 5 and 2. Since the number of factors of 2 is greater than 5, we only need to calculate how many multiples of 5 there are.

class Solution {
    public int trailingZeroes(int n) {
        int number = 0;
        while(n>0){
            n = n/5;
            number = number + n;
        }
        returnnumber; }}Copy the code