For problem statement at 0-999/900-999/980-989/986/problemD.txt this is a correct solution, but verifier at 0-999/900-999/980-989/986/verifierD.go ends with All tests passed can you fix the verifier? package main
import (
"fmt"
"io"
"math"
"math/big"
"os"
"strings"
)
func main() {
bytes, _ := io.ReadAll(os.Stdin)
s := strings.TrimSpace(string(bytes))
n := new(big.Int)
n.SetString(s, 10)
if n.Cmp(big.NewInt(4)) <= 0 {
fmt.Println(n)
return
}
B := n.BitLen()
var log3_n float64
if B <= 60 {
x := float64(n.Int64())
log3_n = math.Log(x) / math.Log(3)
} else {
shift := B - 60
n_shifted := new(big.Int).Rsh(n, uint(shift))
x := float64(n_shifted.Int64())
ln_n := math.Log(x) + float64(shift)*math.Ln2
log3_n = ln_n / math.Log(3)
}
S_est := int(3 * log3_n)
S := S_est - 2
if S < 4 {
S = 4
}
currP := P(S)
big2 := big.NewInt(2)
big3 := big.NewInt(3)
big4 := big.NewInt(4)
for currP.Cmp(n) < 0 {
S++
if S%3 == 1 {
currP.Quo(currP, big3)
currP.Mul(currP, big4)
} else {
currP.Quo(currP, big2)
currP.Mul(currP, big3)
}
}
fmt.Println(S)
}
func P(S int) *big.Int {
if S <= 4 {
return big.NewInt(int64(S))
}
res := big.NewInt(1)
k := S / 3
rem := S % 3
if rem == 1 {
k -= 1
rem = 4
} else if rem == 0 {
rem = 1
}
base := big.NewInt(3)
exp := big.NewInt(int64(k))
res.Exp(base, exp, nil)
if rem != 1 {
res.Mul(res, big.NewInt(int64(rem)))
}
return res
}