172.go 509 B

12345678910111213141516171819202122232425262728293031
  1. package main
  2. import (
  3. "math"
  4. )
  5. // ???
  6. func trailingZeroesOld(n int) int {
  7. cnt := 0
  8. for i := 5; i <= n; i += 5 {
  9. cnt += int(math.Log(float64(i)) / math.Log(5))
  10. }
  11. return cnt
  12. }
  13. func trailingZeroes(n int) int {
  14. var res int
  15. for n > 0 {
  16. n /= 5
  17. res += n
  18. }
  19. return res
  20. }
  21. // func main() {
  22. // fmt.Println(trailingZeroes(3))
  23. // fmt.Println(trailingZeroes(7))
  24. // fmt.Println(trailingZeroes(10))
  25. // fmt.Println(trailingZeroes(100))
  26. // fmt.Println(int(math.Log10(float64(125)) / math.Log10(5)))
  27. // }