(***leetcode_Math)Factorial Trailing Zeroes

来源:互联网 发布:resset数据库 编辑:程序博客网 时间:2024/06/03 09:42

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

Note: Your solution should be in logarithmic time complexity.

Credits:
Special thanks to @ts for adding this problem and creating all test cases.

结尾0只能由因素5、10、15得到,注意就是25,125中5的个数!

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


0 0