Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "math"
- "strconv"
- )
- func DigitsBeforeNumber(number int64) int64{
- if number > 0 && number < 10{ return number-1}
- var tmp int64
- digitsInNumber := int64(math.Log10(float64(number)))+1
- answer := digitsInNumber * (number - int64(math.Pow(10, float64(digitsInNumber)-1)))
- digitsInNumber-=1
- tmp = 0
- for digitsInNumber > 0{
- if digitsInNumber == 1{
- tmp += 9
- }else{
- tmp = (tmp+9*digitsInNumber)*10
- }
- digitsInNumber-=1
- }
- return answer + tmp
- }
- func main() {
- var n int64
- fmt.Scan(&n)
- var L, R, mid int64
- L = 1; R = int64(math.Pow(2,55))
- for R-L > 1{
- mid = (R+L)/2
- digitsBeforeNumber := DigitsBeforeNumber(mid)
- if digitsBeforeNumber > n{R = mid}else{L = mid}
- }
- foundDigit := strconv.FormatInt(L, 10)[n-DigitsBeforeNumber(L)]
- fmt.Println(foundDigit-'0')
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement