leetcode-172-factorial trailing zeroes

Problem Description:

Given an integer n, return the number of trailing zeroes in n!.

Note: Your solution should be in logarithmic time complexity.

题目大意:

给一个整数N,返回n的阶乘的结果中末尾0的个数。

Solutions:

其实很简单,就是考的1-n中有几个5的因子,注意到5的次幂有不止1个因子5即可。

Code in C++:

class Solution {
public:
    int trailingZeroes(int n) {
        int count=0;
        while(n>1)
        {
            count+=n/5;
            n/=5;
        }
       return count; 
    }
};