diff --git a/go/count-good-numbers.go b/go/count-good-numbers.go new file mode 100644 index 0000000..c18bd3d --- /dev/null +++ b/go/count-good-numbers.go @@ -0,0 +1,22 @@ +package main + +const ( + MOD int64 = 1000000007 +) + +func countGoodNumbers(n int64) int { + quickmul := func(x, y int64) int64 { + res := int64(1) + for y > 0 { + if y%2 == 1 { + res = (res * x) % MOD + } + x = (x * x) % MOD + y /= 2 + } + + return res + } + + return int((quickmul(5, (n+1)/2) * quickmul(4, n/2)) % MOD) +}