From 96f59f9f54fcee3abcbfdfc28fd92f68243507d5 Mon Sep 17 00:00:00 2001 From: Matej Focko <me@mfocko.xyz> Date: Sun, 13 Apr 2025 21:58:53 +0200 Subject: [PATCH] =?UTF-8?q?go:=20add=20=C2=AB1922.=20Count=20Good=20Number?= =?UTF-8?q?s=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit URL: https://leetcode.com/problems/count-good-numbers/ Signed-off-by: Matej Focko <me@mfocko.xyz> --- go/count-good-numbers.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 go/count-good-numbers.go 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) +}