Hat ' s Fibonacci
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 9677 Accepted Submission (s): 3210
Problem Descriptiona Fibonacci sequence is calculated by adding the previous, and the sequence, with the first Members being both 1.
F (1) = 1, f (2) = 1, f (3) = 1,f (4) = 1, f (n>4) = f (n-1) + f (n-2) + f (n-3) + f (n-4)
Your task is to take a number as input, and print that Fibonacci number.
Inputeach line would contain an integers. Process to end of file.
Outputfor each case, output the result with a line.
Sample Input100
Sample Output4203968145672990846840663646 Note:no generated Fibonacci number in excess of 2005 digits'll be in the test Data, ie. F () = 66526 has 5 digits.
Author hat.
RECOMMENDIGNATIUS.L | We have carefully selected several similar problems for you:1753 1865 1715 1133 1297 This problem is summed up with large numbers, with the elements of the array representing the numbers of the various digits of the large number, (for example, 123, One technique that can be a[0]=3,a[1]=2,a[2]=1 is to learn on the web that each array element stores eight-bit numbers to improve efficiency. Pre-processing and then entering data. Test instructions: According to the formula of the problem, but the number is particularly large, to use the number of assembly. (large number of questions) enclose the code:
1#include <iostream>2#include <cstdio>3 using namespacestd;4 inta[10000][260]= {0};//each element can store 8 digits, so a 2005-bit can be stored with 260 array elements. 5 voidInit ()6 {7 inti,j;8a[1][0]=1;//assigning an initial value9a[2][0]=1;Tena[3][0]=1; Onea[4][0]=1; A for(i=5; i<10000; i++) - { - for(j=0; j<260; J + +) thea[i][j]=a[i-1][j]+a[i-2][j]+a[i-3][j]+a[i-4][j]; - for(j=0; j<260; J + +)//every eight digits consider rounding - if(a[i][j]>100000000) - { +a[i][j+1]+=a[i][j]/100000000; -a[i][j]=a[i][j]%100000000; + } A } at } - intMain () - { - intn,i,j; - init (); - while(~SCANF ("%d",&N)) in { - for(i=259; i>=0; i--) to if(a[n][i]!=0)//does not output a high 0 + Break; -printf"%d", A[n][i]); the for(j=i-1; j>=0; j--) *printf"%08d", A[n][j]);//each element stores eight digits, so the control output bit is 8 and the left side is 0 $printf"\ n");Panax Notoginseng } - return 0; the}
HDU 1250 Hat ' s Fibonacci