题解 | #阶乘末尾0的数量#
阶乘末尾0的数量
http://www.nowcoder.com/practice/aa03dff18376454c9d2e359163bf44b8
public class Solution {
/**
* the number of 0
* @param n long长整型 the number
* @return long长整型
*/
public long thenumberof0 (long n) {
// write code here
//因为一个数的阶乘只有是5或5的倍数乘以2的时候才会出现尾随零
long sum = 0;
int k = 5;
while(n > 0){
sum += n/k;
n = n/k;
}
return sum;
}
}