Hat ' s Fibonacci
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 10525 Accepted Submission (s): 3483
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
-------------------------------------------------
Import Java.math.BigDecimal;
Import Java.util.Scanner;
public class main1250{
public static void Main (String args[]) {
Scanner cin=new Scanner (system.in);
BigDecimal []a=new bigdecimal[10007];
A[0]=new BigDecimal (1);
A[1]=new BigDecimal (1);
A[2]=new BigDecimal (1);
A[3]=new BigDecimal (1);
for (int i=4;i<10007;i++)
A[i]=a[i-1].add (A[i-2]). Add (A[i-3]). Add (a[i-4]);
while (Cin.hasnext ()) {
int N=cin.nextint ();
System.out.println (a[n-1]);
}
}
}
-----------------
Note:no generated Fibonacci number in excess of 2005 digits would be in the test data, ie. F () = 66526 has 5 digits.
This place should pay attention to the array to open the larger point, the title is not to say only 2005 numbers
HDU1250 (Java) Large number addition problem