Skip to content

Commit a9723b2

Browse files
committed
Add files
1 parent 7172d79 commit a9723b2

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

CSES/Digit Queries.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
#define ll long long
5+
#define m 1e9+7
6+
7+
int main()
8+
{
9+
ios_base::sync_with_stdio(false);
10+
cin.tie(NULL);
11+
cout.tie(NULL);
12+
13+
int q;
14+
cin>>q;
15+
while(q--)
16+
{
17+
ll n,x,i;
18+
cin>>n;
19+
20+
i=1;
21+
x=1;
22+
while(n>i*9*x)
23+
{
24+
n-=i*9*x;
25+
i++;
26+
x*=10;
27+
}
28+
29+
if(n%i==0)
30+
{
31+
cout<<(x-1+n/i)%10;
32+
}
33+
34+
else
35+
{
36+
ll y=x+n/i;
37+
ll j=pow(10,i-n%i);
38+
y/=j;
39+
cout<<y%10;
40+
}
41+
cout<<"\n";
42+
43+
}
44+
45+
}
46+

0 commit comments

Comments
 (0)