Skip to content

Commit

Permalink
new: CSES Introductory problems
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-besbes committed Oct 11, 2024
1 parent 40d6453 commit 8f7adc7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions solutions/CSES/Introductory Problems/2431 - Digit Queries.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <bits/stdc++.h>
using namespace std;

void solve() {
long long k;
cin >> k;
k--;
long long cur = 9, d = 1;
while (k >= d * cur) k -= d * cur, d++, cur *= 10;
long long pref = cur / 9, offset = k / d;
long long nb = offset + pref;
long long pos = d - (k % d) - 1;
while (pos) nb /= 10, pos--;
cout << nb % 10 << "\n";
}

int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);

int t = 1;
cin >> t;
while (t--) solve();
}

0 comments on commit 8f7adc7

Please sign in to comment.