暑假一直没过,这次过了。。不易- -。10算两位数哦~
#include <iostream> #include <math.h> using namespace std; #define M 50000 long long a[M], s[M]; void init() { a[1] = s[1] = 1; for (int i = 2; i < M; i++) { a[i] = a[i - 1] + (int)(log10((double)i) + 1); s[i] = s[i - 1] + a[i]; } } int solve(int x) { int i = 1; while (s[i] < x) i++; int pos = x - s[i - 1]; int len = 0; for (i = 1; len < pos; i++) len += (int)log10(i*1.0) + 1; return (i - 1) / (int)pow((double)10, (len - pos)) % 10; } int main() { int t; init(); cin>>t; while (t--) { int n; cin>>n; cout << solve(n) << endl; } }