Maifo Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 11137 accepted submission (s): 3769
Problem descriptionfibonacci series, which is defined as follows:
F (1) = F (2) = 1
F (n) = f (n-1) + f (n-2) n> = 3.
Calculate the value of the nth term.
Input the first behavior is an integer N, And the next n behavior is an integer Pi (1 <= pI <= 1000 ).
Output is n rows, and each row corresponds to F (PI ).
Sample Input
512345
Sample output
11235
# Include <stdio. h> # include <string. h> char DP [1002] [1000]; char Buf [1000]; void CAL (char str1 [], char str2 [], char STR []) {int len1 = strlen (str1), id = 0; int len2 = strlen (str2), I; memset (BUF, 0, sizeof (BUF )); while (len1> 0 & len2> 0) BUF [ID ++] = str1 [-- len1]-'0' + str2 [-- len2]-'0 '; while (len1> 0) BUF [ID ++] = str1 [-- len1]-'0'; while (len2> 0) buf [ID ++] = str2 [-- len2]-'0'; for (I = 0; I <= ID; ++ I) if (BUF [I]> 9) {++ Buf [I + 1]; Buf [I]-= 10;} If (! Buf [ID]) -- ID; I = 0; while (ID> = 0) STR [I ++] = Buf [ID --] + '0 '; STR [I] = '\ 0';} int main () {DP [1] [0] = DP [2] [0] = '1 '; DP [1] [1] = DP [2] [1] = '\ 0'; int I, n; for (I = 3; I <= 1000; + + I) Cal (DP [I-1], DP [I-2], DP [I]); scanf ("% d", & N); While (n --) {scanf ("% d", & I); printf ("% s \ n", DP [I]) ;}return 0 ;}