Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cstring>
- #include <algorithm>
- #include <fstream>
- #include <map>
- #include <stack>
- using namespace std;
- typedef long long ll;
- const int INF = 1e9;
- int main()
- {
- ios_base::sync_with_stdio(false);
- // ifstream cin("in.txt");
- int q;
- cin >> q;
- while(q--) {
- ll k;
- cin >> k;
- if(k <= 9) {
- cout << k << endl;
- continue;
- }
- ll power_of_9 = 9;
- ll sum = 0;
- ll digits = 1;
- ll current_pow = 1;
- while(sum + (power_of_9 * digits) <= k) {
- sum += (power_of_9 * digits);
- power_of_9 *= 10;
- digits++;
- current_pow *= 10;
- }
- if(k == sum) {
- cout << 9 << endl;
- continue;
- }
- k--;
- current_pow += (k - sum) / digits;
- ll rem = ((k - sum) % digits);
- rem = digits - rem;
- rem -= 1;
- while(rem--) {
- current_pow /= 10;
- }
- cout << (current_pow % 10) << endl;
- }
- return 0;
- }
- // 9 + 180
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement