HDU 1597 find the nth digitproblem description hypothesis:
S1 = 1
S2 = 12
S3. = 123
S4 = 1234
.........
S9 = 123456789
S10 = 1234567891
S11= 12345678912
............
S18= 123456789123456789
..................
Now we connect all strings
S = 1121231234 ...... 123456789123456789112345678912 .........
Can you tell me the nth number in the S string?
The input is a number K, which indicates K queries.
Each row in the next K Rows has an integer N (1 <=n <2 ^ 31 ).
For each n, output the nth number in S.
Sample input61234510
Sample output112124
CodeG ++
# Include <iostream>
# Include <cmath>
Using namespace STD ;
Int Main ()
{
Long long T , N , S , I ;
CIN > T;
While ( T --)
{
CIN > N ;
For ( I = SQRT ( 2 * N ); I > 0 ; I --)
{
If ((( I *( I + 1 ))/ 2 < N ))
Break ;
}
S = N -(( I *( I + 1 ))/ 2 );
If ( S% 9 = 0 )
Cout < 9 < Endl ;
Else
Cout < S % 9 < Endl ;
}
Return 0 ;
}
// Note the Formula 1 + 2 +... + X = (1 + x) * X/2 applications