MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / main

Function main

CSES/Intro/DigitQueries.cc:14–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12}
13
14int main(){
15 ios_base::sync_with_stdio(false),cin.tie(nullptr);
16
17 int Q; cin >> Q;
18 while (Q--) {
19 int64_t K; cin >> K;
20 int64_t n = 1, sum = 0;
21
22 while (K >= sum) {
23 sum = sum + 9 * n * power(10,n-1);
24 n++;
25 }
26 n--;
27
28 // Digits away
29 int64_t away = (sum - K) / n;
30 int64_t rem = (sum - K) % n;
31
32 // calculate Number
33 int64_t number = (power(10,n) - 1) - away;
34
35 string No = to_string(number);
36 cout << No[(No.length() - 1 - rem)] << endl;
37 }
38 return 0;
39}
40
41

Callers

nothing calls this directly

Calls 2

lengthMethod · 0.80
powerFunction · 0.70

Tested by

no test coverage detected