题解 | 无限长正整数排列字符串 | 按位分组定位法
无限长正整数排列字符串
https://www.nowcoder.com/practice/82c92d2321bb4220a3006d52a95a8bdd
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
using ll=long long;
int main() {
ios::sync_with_stdio(false);cin.tie(nullptr);
int n; cin>>n;
ll len=0;
int digit=1;
ll count=9;
while (n>len+digit*count) {
len+=digit*count;
++digit;
count*=10;
}
ll remain=n-len;
ll num=(ll)pow(10,digit-1)+(remain-1)/digit;
int pos=(remain-1)%digit;
string s=to_string(num);
cout<<s[pos]<<'\n';
return 0;
}