Http://poj.org/problem? Id = 1019
Question:
Number Sequence
| Time limit:1000 ms |
|
Memory limit:10000 K |
| Total submissions:24168 |
|
Accepted:6466 |
Description
A single positive integer I is given. write a program to find the digit located in the position I in the sequence of Number Groups s1s2... SK. each group SK consists of a sequence of positive integer numbers ranging from 1 to K, written one after another.
For example, the first 80 digits of the sequence are as follows:
11212312341234512345612345671234567812345678912345678910123456789101112345678910
Input
The first line of the input file contains a single integer T (1 ≤ T ≤ 10), the number of test cases, followed by one line for each test case. the line for a test case contains the single integer I (1 ≤ I ≤2147483647)
Output
There shoshould be one output line per test case containing the digit located in the position I.
Sample Input
283
Sample output
22
Source
Tehran 2002, first Iran nationwide Internet programming contest
For a mathematical problem, the question is to give a string of 1 12 123 1234 12345 123456 .... Such a number
The number I represents. The trick of this question lies in the difference between the number of I and the number of digits of the I-1, the formula can be used:(INT) log10 (double (I) + 1. When the number is the power of 10, the number changes.
Table hitting: The table is not typed at the beginning, and the time has timed out ~~~~ Haha... finally, I know what a table is called !!
# Include < Math. h >
# Include < Iostream >
Using Namespace STD;
Unsigned Int A [ 31270 ], S [ 31270 ];
Void Reset () // Table Creation
{
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 ) Log10 (( Double ) I) + 1 ;
}
Int K = TMP - Pos;
Printf ( " % D \ n " , (I - 1 ) / ( Int ) Pow ( 10.0 , K) % 10 ); /* Right to left, for example, 123456, K = 2, the result is 4. */
}
Return 0 ;
}
This question is relatively simple ~~~~~~