题意描述
思路
观察发现,每次到
9
,
99
,
999
,
9999...
9,99,999,9999...
9,99,999,9999...以后,等差
d
d
d就会多加1。例如,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
1,2,3,4,5,6,7,8,9
1,2,3,4,5,6,7,8,9这段数字的位数等差为1,
10
,
11...99
10,11...99
10,11...99,这段数字的位数等差就变成2了。我们可以根据这个性质,求出来k对应的数是属于哪一段,然后暴力的构造出字符串即可。
AC代码
#include<bits/stdc++.h>
#define x first
#define y second
#define PB push_back
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define rep(x,l,u) for(ll x=l;x<u;x++)
#define rrep(x,l,u) for(ll x=l;x>=u;x--)
#define sz(x) x.size()
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std
;
typedef unsigned long long ull
;
typedef pair
<int,int> PII
;
typedef pair
<long,long> PLL
;
typedef pair
<char,char> PCC
;
typedef long long ll
;
const int N
=2*1e5+10;
const int M
=1e6+10;
const int INF
=0x3f3f3f3f;
const int MOD
=1e9+7;
ll f
[10];
void solve(){
ll n
;cin
>>n
;
ll cnt
=0,k
=1,idx
=0,t
=1,cpy
=n
;
while(1){
cnt
++;
n
-=k
;
if(n
<=0){
n
+=k
;
break;
}
if(cnt
==f
[idx
]){
idx
++;
t
++;
}
k
+=t
;
}
string s
;
rep(i
,1,cnt
+1) s
+=to_string(i
);
cout
<<s
[n
-1]<<endl
;
}
int main(){
IOS
;
f
[0]=9;
rep(i
,1,10) f
[i
]=f
[i
-1]*10+9;
int t
;cin
>>t
;
while(t
--)
solve();
return 0;
}