求末尾多少0可以表示为 n*10—>n*2*5。即求分解后有多少个5.
public class S_172 {
public int trailingZeroes(int n) {
// 提出一个特殊情况
if (n <= 1) {
return 0;
}
int result = 0;
while (n != 0) {
result += n / 5;
// 注意:需要得到每个数分解质因子后5的个数
n = n / 5;
}
return result;
}
}