-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDigitQueries.cpp
More file actions
54 lines (47 loc) · 1010 Bytes
/
Copy pathDigitQueries.cpp
File metadata and controls
54 lines (47 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <bits/stdc++.h>
using namespace std;
#define int unsigned long long
int k;
string to_String(int n)
{
stringstream ss;
ss << n;
return ss.str();
}
void giai()
{
cin >> k;
int socs = 1;
int soso = 9;
int whocare = 0;
while(whocare + soso * socs < k)
{
whocare += (soso * socs);
socs++;
soso *= 10;
}
//whocare + soso * socs >= k && whocare < k
//so can tim co (socs) chu so
int kcach = k - whocare;
int sobatdau = 1;
for(int i = 1; i < socs; i++) sobatdau *= 10;
int sothumay = (kcach + socs - 1) / socs;
//cout << kcach << ' ';
int sodo = sobatdau + sothumay - 1;
string taocare = to_String(sodo);
int momke = kcach % socs;
if(momke == 0) cout << taocare[taocare.size() - 1];
else cout << taocare[momke - 1];
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while(t--)
{
giai();
cout << "\n";
}
}