1234567891011121314151617181920212223242526272829303132 |
- package main
- import (
- "fmt"
- "math"
- )
- // ???
- func trailingZeroesOld(n int) int {
- cnt := 0
- for i := 5; i <= n; i += 5 {
- cnt += int(math.Log(float64(i)) / math.Log(5))
- }
- return cnt
- }
- func trailingZeroes(n int) int {
- var res int
- for n > 0 {
- n /= 5
- res += n
- }
- return res
- }
- func main() {
- fmt.Println(trailingZeroes(3))
- fmt.Println(trailingZeroes(7))
- fmt.Println(trailingZeroes(10))
- fmt.Println(trailingZeroes(100))
- fmt.Println(int(math.Log10(float64(125)) / math.Log10(5)))
- }
|