-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40d6453
commit 8f7adc7
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
solutions/CSES/Introductory Problems/2431 - Digit Queries.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |