设计一个算法,计算出n阶乘中尾部零的个数
public long trailingZeros(long n) {
// write your code here, try to do it without arithmetic operators.
long count = 0;
long temp = n/5;
while(temp != 0){
count = count+temp;
temp = temp/5;
}
return count;
}
写完啦~可以吃饭了
本文介绍了一种计算n的阶乘(n!)结果中尾部零的个数的算法。该算法通过不断除以5并累加商来确定尾部零的数量,实现了高效计算。
932





