Factorial Trailing Zeroes

来源:互联网 发布:怎么启用flash插件 mac 编辑:程序博客网 时间:2024/05/22 12:01

Factorial Trailing Zeroes

  

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

Note: Your solution should be in logarithmic time complexity.

思路:有多少个2与5相乘,就有多少个0,由于2远多于5,就是算有多少个5。

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


0 0