[leetcode 172] Factorial Trailing Zeroes

来源:互联网 发布:编程大赛题目 编辑:程序博客网 时间:2024/06/05 08:12

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

Note: Your solution should be in logarithmic time complexity.

class Solution {public:    int trailingZeroes(int n) {        int power = 1;        int c = 0;        int f = (int) (n/(pow(5, power)));            while(f > 0){            c += f;            f = (int) (n/(pow(5, ++power)));        }        return c;    }};


0 0
原创粉丝点击