1、阶乘后的0https://leetcode-cn.com/problems/factorial-trailing-zeroes/
给定一个整数
n
,返回n!
结果中尾随零的数量。提示n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1
int trailingZeroes(int n){
if(n<5){
return 0;
}else{
return n/5+trailingZeroes(n/5);
}
}
1、 当n<5的时候,由于n!中没有以10为因子的数,所以,没有0
2、而且2的倍数肯定是要比5的倍数多的,没出现这么一对,就意味着会出现一个0,我们判断5的倍数的个数就能得到,于是n每次除以5