Link: poj 1019
Question: There is a sequence of numbers
112123123412345123456123456712345678123456789123456789101234567891011...
The input position n calculates the nth digit of this string.
Analysis: The Simulation Group considers 1 as 1st groups, 12 as 2nd groups, and 123 as 3rd groups...
Group I is a positive integer that stores the number sequence as [1, I], but the length of Group I is not necessarily I,
It is known that the range of n in the nth position of the input is (1 ≤ n ≤ 2147483647 ),
Then at least 31268 groups are required to bring the number sequence to 2,147,483,647th bits.
Key point: Number of I digits = (int) log10 (double) I) + 1
# Include <stdio. h> # include <math. h> # define M 31300 _ int64 a [M], s [M]; void num_potion () {int I; a [1] = s [1] = 1; for (I = 2; I <M; I ++) {a [I] = a [i-1] + (int) log10 (double (I) + 1; // a [I] is the length of the I group s [I] = s [i-1] + a [I]; // s [I] is the length of the first I group} int locat (int n) {int I = 1, m = 0; while (s [I] <n) // Determine the nth bit as the nth group I ++; n-= s [i-1]; // calculate the length of nth bit in the nth group I = 1; m <n; I ++) m + = (int) log10 (double (I) + 1; // The value of the number of nth bits m = (i-1) /(int) pow (10 ., m-n) % 10; // calculate the nth digit return m;} int main () {int T, n, m; num_potion (); scanf ("% d", & T); while (T --) {scanf ("% d", & n); m = locat (n ); printf ("% d \ n", m);} return 0 ;}
Poj 1019 Number Sequence (composite mathematics)