// N!中包含0的个数
// 其实关键问题是转化为统计5的个数 因为偶数出现次数远大于5
//偶数*5就能凑0,由于偶数远大于5出现次数,所以一个5就能产生一个0
// 公式: count([N/5] + [N/5/5] + [N/5/5...])
package main
import (
"fmt"
)
func fzcount(n int) int {
tmp, count := 0, 0
for {
tmp = n / 5
if tmp > 0 {
count += tmp
n = tmp
} else {
return count
}
}
return count
}
func main() {
test := []int{5, 10, 15, 19, 20, 100}
for _, val := range test {
fmt.Printf("%d! has zero count:%d\n", val, fzcount(val))
}
}
输出结果:
5! has zero count:1
10! has zero count:2
15! has zero count:3
19! has zero count:3
20! has zero count:4
100! has zero count:24