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:
Matej Focko 2025-04-13 21:58:53 +02:00
parent 2fa0295ff1
commit 96f59f9f54
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

22
go/count-good-numbers.go Normal file
View 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)
}