1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| #include <iostream> #include <cmath> using namespace std;
int main() { long long n; cin >> n;
long long grp_len[99999], grp_idx[99999]; grp_len[0] = 0; for (int i = 1; i < 99999; ++i) { int len = log10(i) + 1; grp_len[i] = grp_len[i - 1] + len; }
grp_idx[0] = 0; for (int i = 1; grp_idx[i - 1] <= (~0u >> 1); ++i) { grp_idx[i] = grp_idx[i - 1] + grp_len[i]; }
while (cin >> n) { int i, k; for (i = 1; grp_idx[i] < n; ++i); int j = n - grp_idx[i - 1]; for (k = 1; grp_len[k] < j; ++k); int ans = k; for (i = 0; i < grp_len[k] - j; ++i) { ans /= 10; } ans %= 10; cout << ans << endl; }
return 0; }
|