Factorial Trailing Zeroes
2015-03-05 21:00 笨笨的老兔子 阅读(137) 评论(0) 编辑 收藏 举报求一个整数n的阶乘后面有几个0
思路:0肯定是由5*2=10得到,2的个数肯定远大于5,所以只要数一下n的阶乘的因式分解里有几个5即可。
classSolution{
public:
int trailingZeroes(int n){
int count =0;
while(n)
{
count += n /5;
n = n /5;
}
return count;
}
};