From 8f7adc70619a751dfb6616a3b2d559434beab6d3 Mon Sep 17 00:00:00 2001 From: Omar Besbes <86571415+omar-besbes@users.noreply.github.com> Date: Fri, 11 Oct 2024 23:09:24 +0100 Subject: [PATCH] new: CSES Introductory problems --- .../2431 - Digit Queries.cpp | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 solutions/CSES/Introductory Problems/2431 - Digit Queries.cpp diff --git a/solutions/CSES/Introductory Problems/2431 - Digit Queries.cpp b/solutions/CSES/Introductory Problems/2431 - Digit Queries.cpp new file mode 100644 index 0000000..e4c0d47 --- /dev/null +++ b/solutions/CSES/Introductory Problems/2431 - Digit Queries.cpp @@ -0,0 +1,25 @@ +#include +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(); +} \ No newline at end of file