Advertisement
EWTD

Untitled

Sep 16th, 2021
1,675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.83 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "math"
  6.     "strconv"
  7. )
  8.  
  9. func DigitsBeforeNumber(number int64) int64{
  10.     if number > 0 && number < 10{ return number-1}
  11.     var tmp int64
  12.     digitsInNumber := int64(math.Log10(float64(number)))+1
  13.     answer := digitsInNumber * (number - int64(math.Pow(10, float64(digitsInNumber)-1)))
  14.     digitsInNumber-=1
  15.     tmp = 0
  16.     for digitsInNumber > 0{
  17.         if digitsInNumber == 1{
  18.             tmp += 9
  19.         }else{
  20.             tmp = (tmp+9*digitsInNumber)*10
  21.         }
  22.         digitsInNumber-=1
  23.     }
  24.     return answer + tmp
  25. }
  26. func main() {
  27.     var n int64
  28.     fmt.Scan(&n)
  29.     var L, R, mid int64
  30.     L = 1; R = int64(math.Pow(2,55))
  31.     for R-L > 1{
  32.         mid = (R+L)/2
  33.         digitsBeforeNumber := DigitsBeforeNumber(mid)
  34.         if digitsBeforeNumber > n{R = mid}else{L = mid}
  35.     }
  36.     foundDigit := strconv.FormatInt(L, 10)[n-DigitsBeforeNumber(L)]
  37.     fmt.Println(foundDigit-'0')
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement