Poj 1019 Number Sequence (composite mathematics)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.