We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 40d6453 commit 8f7adc7Copy full SHA for 8f7adc7
solutions/CSES/Introductory Problems/2431 - Digit Queries.cpp
@@ -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