topic:
Description
is given of a single positive integer i. Programming to find the set of digits located S1S2 ... Sk digital position i of the sequence. Each group consists of a series Sk positive integers ranging from 1 to k, written one by one.
For example, the first 80-digit sequence is as follows:
11212312341234512345612345671234567812345678912345678910123456789101112345678910
enter
the first line of the input file contains an integer t (1≤t≤10), the number of test cases, each test followed by a line. The test line contains a single integer i (1≤i≤2147483647)
output of
each test case should have an output line, which comprises a digital located at position i.
Sample input
2
. 8
. 3
sample output
2
2
#include<math.h> #include<iostream> using namespace std; unsigned int a[31270],s[31270]; void reset()//打表 { int i; a[1]=1; s[1]=1; for(i=2;i<31270;i++) { a[i]=a[i-1]+(int)log10((double)i)+1; s[i]=s[i-1]+a[i]; } } int main() { int T; int n; int i; scanf("%d",&T); reset(); while(T--) { scanf("%d",&n); i=1; while(s[i]<n) i++; int pos=n-s[i-1]; int tmp=0; for(I = . 1 ; tmp <POS; I ++ ) { tmp + = ( int ) loglO (( Double ) I) + . 1 ; } int K = tmp- POS; the printf ( " % D \ n- " , (I- . 1 ) / ( int ) POW ( 10.0 , K)% 10 ); / * right to left request, such as 123456, k = 2, the result is. 4 * / } return 0 ; }
Source: https: //www.cnblogs.com/kuangbin/archive/2011/07/21/2113279.html