DuXiong xuefeiboI
Time Limit: 2000/1000 ms (C/other) memory limit: 65535/32768 K (C/other)
This organizing committee recommends C and C ++
Problem description
Du Xiong has always been very interested in mathematics. I recently learned the Fibonacci series and showed you a number string called the "Fibonacci" string:
11235813471123581347112358 ........
You can see at a glance that this string is constructed in this way:
1. First write down two ~ The numbers A and B in the range of 9 constitute the AB string;
2. Add the two digits at the end of the string to the end of the string.
The string shown by Du Xiong above is a string constructed from a = B = 1.
Obviously, step 2 is continuously performed after step 1, and the number string can be infinitely expanded. Now du Xiong wants to know the nth digit of the string.
Input
The first act of the input data is an integer T (1 <=t <= 1000), indicating that there are T groups of test data;
Each group of test data has three positive integers A, B, n (0 <= A, B <10, 0 <n <= 10 ^ 9 ).
Output
For each group of test data, output a line "case # C: ANS" (excluding quotation marks)
C is the number of test data groups, starting from 1.
Sample Input
3
1 1 2
1 1 8
1 4 8
Sample output
Case #1: 1
Case #2: 3
Case #3: 9
Hint
For the first and second groups of data, the string is 112358134711235 ......
For the third group of data, the string is 14591459145914 ......
This is the cycle section.
The Code is as follows:
# Include <cstdlib> # include <cstdio> # include <iostream> using namespace STD; int loc [105]; int T, A, B, n, Pos; char s [200]; bool action () {int x = s [pos-2], y = s [pos-1]; int z = x + y; If (z> = 10) {s [POS] = z/10; s [POS + 1] = z % 10; POS + = 2; // translated two units} else {s [POS] = z; POS + = 1; // translated a unit} X = s [pos-2], y = s [pos-1]; If (loc [x * 10 + Y]! =-1) {return false;} loc [x * 10 + Y] = pos-2; return true;} int main () {int CA = 0; scanf ("% d", & T); While (t --) {memset (LOC, 0xff, sizeof (LOC); Pos = 3; scanf ("% d", & A, & B, & N); s [1] = A, s [2] = B; while (1) {If (! Action () {break ;}} printf ("case # % d:", ++ CA); If (n <POS) {printf ("% d \ n ", s [N]);} else {int x = s [pos-2], y = s [pos-1]; n-= (loc [x * 10 + Y]-1 ); N % = (POS-2-loc [x * 10 + Y]); printf ("% d \ n ", s [loc [x * 10 + Y] + n-1]) ;}} return 0 ;}