题解 | #阶乘末尾0的数量#
阶乘末尾0的数量
http://www.nowcoder.com/practice/aa03dff18376454c9d2e359163bf44b8
import java.util.*;
//暴力解法:时间复杂度大,超时
public class Solution {
/**
* the number of 0
* @param n long长整型 the number
* @return long长整型
*/
public long thenumberof0 (long n) {
// write code here
//特殊值处理
if(n == 0){
return 0;
}
long m = 1;
//求阶乘
for(long i=1;i<=n;i++){
m = m*i;
}
//求个数
int count = 0;
long remainder = m%10;
long temp = m/10;
while(remainder==0){
count++;
remainder = temp%10;
temp = temp/10;
}
return count;
}
}