Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include<bits/stdc++.h>
- #include<iostream>
- #include<string>
- #include<algorithm>
- #define long long long
- #define nln '\n'
- using namespace std;
- string num2string(long num)
- {
- string str = "";
- while (num > 0)
- {
- str += (num%10)+'0';
- num /= 10;
- }
- reverse(str.begin(), str.end());
- return str;
- }
- int main()
- {
- cin.tie(0)->sync_with_stdio(0);
- cout.tie(0)->sync_with_stdio(0);
- long n, k, len = 0;
- cin >> n >> k;
- string st1 = "", st2 = "";
- for (long i = 1; i <= n; ++i)
- {
- st2 = num2string(i) + st1 + st1;
- len += abs((long)st1.size()-(long)st2.size());
- st1 = st2;
- if ((long)st1.size() > k)
- st1.erase(st1.begin()+k+1, st1.end());
- }
- if (k > len)
- cout << "-1" << nln;
- else
- cout << st2[k-1] << nln;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment