1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| #include <bits/stdc++.h> #define N 20 #define int long long #define IOS ios::sync_with_stdio(0),cin.tie(0) using namespace std; int n,pref[N],p[20];
void init(){ p[0] = 1; for(int i=1;i<19;i++){ p[i] = p[i-1] * 10; } pref[1] = 9; for(int i=2;i<18;i++){ pref[i] = p[i-1] * 9 * i; } }
void solve(){ int ind = 1; while(n > pref[ind])n -= pref[ind++]; n--; int x = n / ind; int y = n % ind; int ans = p[ind-1] + x; string temp = to_string(ans); cout<<temp[y]<<"\n"; }
signed main(){ IOS; init(); int t;cin>>t; while(t--){ cin>>n; solve(); } }
|