public class jiecheng {
/**
* 给定一个非负整数N,返回N!结果的末尾为0的数量
* @param args
*/
public static void main(String[] args) {
thenumberof0(5);
}
/**
* the number of 0
* @param n long长整型 the number
* @return long长整型
*/
//要相乘产生0,那肯定是与5相乘的结果。对n!如果分解质因数的话,结果为0的个数只与2与5的个数有关,每一次2*5就能产生一个0。因为2的个数肯定要大于5的个数,所以只要关注5的个数就可以了.
public static long thenumberof0 (long n) {
// write code here
long ret=0;
long i=5;
while(i<=n){
ret=ret+n/i;
i=i*5;
}
return ret;
}
}