Advertisement
Josif_tepe

Untitled

Mar 16th, 2021
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <fstream>
  6. #include <map>
  7. #include <stack>
  8. using namespace std;
  9. typedef long long ll;
  10. const int INF = 1e9;
  11.  
  12. int main()
  13. {
  14.     ios_base::sync_with_stdio(false);
  15. //    ifstream cin("in.txt");
  16.     int q;
  17.     cin >> q;
  18.     while(q--) {
  19.         ll k;
  20.         cin >> k;
  21.         if(k <= 9) {
  22.             cout << k << endl;
  23.             continue;
  24.         }
  25.         ll power_of_9 = 9;
  26.         ll sum = 0;
  27.         ll digits = 1;
  28.         ll current_pow = 1;
  29.         while(sum + (power_of_9 * digits) <= k) {
  30.             sum += (power_of_9 * digits);
  31.             power_of_9 *= 10;
  32.             digits++;
  33.             current_pow *= 10;
  34.         }
  35.         if(k == sum) {
  36.             cout << 9 << endl;
  37.             continue;
  38.         }
  39.         k--;
  40.         current_pow += (k - sum) / digits;
  41.         ll rem = ((k - sum) % digits);
  42.         rem = digits - rem;
  43.         rem -= 1;
  44.         while(rem--) {
  45.             current_pow /= 10;
  46.         }
  47.        
  48.         cout << (current_pow % 10) << endl;
  49.        
  50.        
  51.     }
  52.    
  53.     return 0;
  54. }
  55. // 9 + 180
  56.  
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement