-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDigit-queries.cpp
More file actions
64 lines (55 loc) · 983 Bytes
/
Digit-queries.cpp
File metadata and controls
64 lines (55 loc) · 983 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
55
56
57
58
59
60
61
62
63
64
// Go to https://artemlos.net/docs/2014/01/MathExploration.pdf before solving
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const int mod = 1e9 +7;
ll power(ll a, ll b)
{
ll res = 1;
while (b > 0)
{
if (b & 1)
{
res = (res * a);
}
a = (a * a);
b >>= 1;
}
return res;
}
void solve()
{
ll k ;
cin>>k;
ll dig = 1 , nex = 9 ;
while (k - (dig * nex) > 0)
{
k -= dig * nex;
nex *= 10;
dig++;
}
ll p = k % dig;
ll num = power(10 , dig-1) + ((k-1)/dig );
//cout<<num << " " <<dig<<" ";
if(p!=0)
{
num = num / power(10 , dig - p);
}
ll ans = num%10;
cout<< ans<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//input test cases
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}