add new solutions
This commit is contained in:
parent
9c2c959a9b
commit
9a10695e8c
29 changed files with 1074 additions and 2 deletions
21
solutions/1/q172/solution.go
Normal file
21
solutions/1/q172/solution.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package q172
|
||||
|
||||
// Note: actually, counting 5 alone is enough since 2 certainly occurs more than 5.
|
||||
|
||||
func trailingZeroes(n int) int {
|
||||
count2, count5 := 0, 0
|
||||
for i := 2; i <= n; i++ {
|
||||
num := i
|
||||
for num%2 == 0 {
|
||||
num /= 2
|
||||
count2++
|
||||
}
|
||||
for num%5 == 0 {
|
||||
num /= 5
|
||||
count5++
|
||||
}
|
||||
}
|
||||
return min(count2, count5)
|
||||
}
|
||||
|
||||
var _ = trailingZeroes
|
||||
Loading…
Add table
Add a link
Reference in a new issue