Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ll long long
- #include <bits/stdc++.h>
- using namespace std;
- const int OO = 1e9;
- const double EPS = 1e-9;
- /*
- ll bs(ll x) {
- ll l = 0;
- ll h = 1e9;
- while(true) {
- ll mid = (h+l)/2;
- ll _s = (mid*(mid+1))/2;
- ll _e = ((mid+1)*(mid+2))/2;
- if(x > _s && x <= _e) {
- return mid;
- }
- if(x <= _s) {
- h = mid-1;
- }
- else {
- l = mid+1;
- }
- }
- }
- */
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- int t;
- cin >> t;
- while(t--) {
- ll x;
- cin >> x;
- ll sum_prev = 0;
- ll sum = 0;
- ll idx;
- for(ll i = 1; ; i++) {
- sum_prev = sum;
- ll _s = 1;
- ll _e = 9;
- ll d = 1;
- while(_s <= i) {
- sum += (min(_e,i)-_s+1)*d;
- d++;
- _s *= 10;
- _e = _e*10 + 9;
- }
- if(x <= sum) {
- idx = i;
- break;
- }
- }
- x -= sum_prev;
- ll curr_sum = 0;
- for(ll i = 1; ; i++) {
- ll length = to_string(i).length();
- curr_sum += length;
- if(curr_sum >= x) {
- cout << to_string(i)[length-1-(curr_sum-x)] << "\n";
- break;
- }
- }
- /*ll m = bs(x);
- //cout << "m is " << m << "\n";
- cout << x-(m*(m+1))/2;
- if(t) {
- cout << "\n";
- }*/
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement