For problem statement at 1000-1999/1200-1299/1210-1219/1216/problemE1.txt this is a correct solution, but verifier at 1000-1999/1200-1299/1210-1219/1216/verifierE1.go ends with All tests passed can you fix the verifier? package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func L(x uint64) uint64 {
res := uint64(0)
p := uint64(1)
for d := uint64(1); p <= x; d++ {
nextP := p * 10
if x < nextP {
res += d * (x - p + 1)
break
} else {
res += d * (nextP - p)
}
p = nextP
}
return res
}
func S(x uint64) uint64 {
res := uint64(0)
p := uint64(1)
L_prev := uint64(0)
for d := uint64(1); p <= x; d++ {
nextP := p * 10
end := x
if end >= nextP {
end = nextP - 1
}
count := end - p + 1
sum := count*L_prev + d*count*(count+1)/2
res += sum
L_prev += d * (nextP - p)
p = nextP
}
return res
}
func main() {
scanner := bufio.NewScanner(os.Stdin)
scanner.Split(bufio.ScanWords)
if !scanner.Scan() {
return
}
q, _ := strconv.Atoi(scanner.Text())
for i := 0; i < q; i++ {
scanner.Scan()
k, _ := strconv.ParseUint(scanner.Text(), 10, 64)
l, r := uint64(0), uint64(2000000000)
x := uint64(0)
for l <= r {
mid := l + (r-l)/2
if S(mid) < k {
x = mid
l = mid + 1
} else {
if mid == 0 {
break
}
r = mid - 1
}
}
rem := k - S(x)
l, r = uint64(0), x+1
y := uint64(0)
for l <= r {
mid := l + (r-l)/2
if L(mid) < rem {
y = mid
l = mid + 1
} else {
if mid == 0 {
break
}
r = mid - 1
}
}
rem2 := rem - L(y)
num := y + 1
numStr := strconv.FormatUint(num, 10)
fmt.Printf("%c\n", numStr[int(rem2)-1])
}
}