Given an integer n, return the number of zeros in the mantissa of the n! result.

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, there is 1 zero in the mantissa.

code section

class Solution {
    public int trailingZeroes(int n) {
        if (n < 5) {
            return 0;
        }
        int count = 0;
        int len = n / 5;
        for (int i = 1; i <= len; i++) {
            count = count + split(5 * i);
        }
        return count;
    }

    public static int split(int n) {
        if (n < 5) {
            return 0;
        }
        int len = 0;
        boolean flag = true;
        while (flag) {
            if (n / 5 < 5) {
                flag = false;
            }
            if (n / 5 % 5 == 0) {
                n = n / 5;
            }
            else {
                flag = false;
            }

            len ++ ;
        }
        return len;
    }    
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325813654&siteId=291194637