go: add «1922. Count Good Numbers»
URL: https://leetcode.com/problems/count-good-numbers/ Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
2fa0295ff1
commit
96f59f9f54
1 changed files with 22 additions and 0 deletions
22
go/count-good-numbers.go
Normal file
22
go/count-good-numbers.go
Normal file
|
@ -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)
|
||||
}
|
Loading…
Add table
Reference in a new issue