Skip to content

Commit 8f7adc7

Browse files
committed
new: CSES Introductory problems
1 parent 40d6453 commit 8f7adc7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
void solve() {
5+
long long k;
6+
cin >> k;
7+
k--;
8+
long long cur = 9, d = 1;
9+
while (k >= d * cur) k -= d * cur, d++, cur *= 10;
10+
long long pref = cur / 9, offset = k / d;
11+
long long nb = offset + pref;
12+
long long pos = d - (k % d) - 1;
13+
while (pos) nb /= 10, pos--;
14+
cout << nb % 10 << "\n";
15+
}
16+
17+
int main() {
18+
ios::sync_with_stdio(false);
19+
cin.tie(0);
20+
cout.tie(0);
21+
22+
int t = 1;
23+
cin >> t;
24+
while (t--) solve();
25+
}

0 commit comments

Comments
 (0)