Advertisement
Ladies_Man

K-th digit of number

Mar 20th, 2014
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.39 KB | None | 0 0
  1. package main
  2. import "fmt"
  3. import "math"
  4.  
  5. func main() {
  6.         var a, i, k, temp int64
  7.     fmt.Scanf("%d", &k)
  8.  
  9.     for ; k >= a; i++ {
  10.         temp = a
  11.         a+=  (int64)(9*math.Pow(10, float64(i))*float64(i+1))
  12.     }
  13.  
  14.     c := i - 1
  15.     d := (k - temp) / i
  16.     temp2 := (int64)(math.Pow(10, float64(c)) + float64(d))
  17.     k = i - (k-temp)%i
  18.    
  19.     for ;k >= 2; k-- { temp2 /= 10 }
  20.     fmt.Printf("%d", temp2%10)
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement