Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1250
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 Input
100
Sample Output
4203968145672990846840663646note:no generated Fibonacci number in excess of 2005 digits would be in the test data, ie. F () = 66526 has 5 digits.
Directly with the large number of Java solution can!
The code is as follows:
Import Java.math.BigInteger; Import java.util.*; Import java.io.*; public class Main {public static void main (string[] args) {//TODO auto-generated method Stubscanner cin = new Scanner (Sys tem.in); BigInteger num[] = new biginteger[10017]; NUM[1] = new BigInteger ("1"); NUM[2] = new BigInteger ("1"); NUM[3] = new BigInteger ("1"); NUM[4] = new BigInteger ("1"); for (int i = 5; I <= 10000; i++) { Num[i] = Num[i-1].add (Num[i-2].add (Num[i-3].add (num[i-4)))); } while (Cin.hasnext ()) { int n = cin.nextint (); System.out.println (Num[n]);}}
just started to learn Java, with three good simple tutorial links:
Floating Calf: (Java class large number practiced hand)
A person's travel: (Java large number processing)
From A Start,as an acmer: (Java BigInteger)
HDU 1250 Hat's Fibonacci (addition of large numbers of Java) + explanation