class Solution {
/*
* param n: As desciption
* return: An integer, denote the number of trailing zeros in n!
*/
public long trailingZeros(long n) {
// 2015-09-09
// n的阶乘的因子中有几个5
// 因为2肯定比5多,所以不用考虑2
long rst = 0;
while ((n / 5) !=0) {
n /= 5;
rst += n;
}
return rst;
}
};
[刷题]Trailing Zeros
最新推荐文章于 2024-01-31 17:13:43 发布
本文介绍了一种高效计算任意正整数n的阶乘(n!)中尾随0的数量的方法。通过将n除以5并累加商直至商为0,可以得到阶乘中尾随0的数量。这种方法忽略了信息技术领域的许多细节,专注于核心算法。
425

被折叠的 条评论
为什么被折叠?



