n的阶乘末尾含0的个数
设计一个算法,计算出n阶乘中尾部零的个数
样例
11! = 39916800,因此应该返回 2
挑战
O(logN)的时间复杂度
原理:ret=n/5 + n/(5*5) + n/(5*5*5) + ⋯
but 没有搞明白
<?php
//O(logN)
function test1($n){
$count = 0;
$temp=(int)($n/5);
while ($temp!=0) {
$count+=$temp;
$temp=(int)($temp/5);
}
return $count;
}
echo test(101)."\n";