序列 \(123456789101112131415161718192021222324252627282930313233343536...\) 是无穷无尽的,现在你要输出它的第 \(k\) 项。\(k \le 10^{12}\)
分步处理
#include <bits/stdc++.h>
using namespace std;
#define int long long
int k;
signed main() {
cin>>k;
if(k<10) {
cout<<k;
return 0;
}
int len=1,cnt=9,pos=0;
while(len*cnt+pos < k) {
pos+=len*cnt;
++len;
cnt*=10;
}
k-=pos+1;
int val=k/len+pow(10,len-1);
cout<<(val/(int)pow(10,len-k%len-1))%10;
}
[CF1177B] Digits Sequence (Hard Edition) - 数学
原文:https://www.cnblogs.com/mollnn/p/12825684.html