172.go 495 B

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