Question link: http://ac.jobdu.com/problem.php? Cid = 1039 & pid = 3
Description:
Description: we all know the Fibonacci series. Now we need to input an integer N. Please output the nth entry of the Fibonacci series. The Fibonacci series is defined as follows: input: the input may contain multiple test examples. For each test case, the input includes an integer N (1<= N <=70). Output: For each test case, the value of the nth Fibonacci series is output. Sample input: 3 sample output:2
Using biginteger in Java can solve the problem quickly, but I still get the runtime error result.
Import java. Math. biginteger; import java. util. example; /* ** Question 4: Fibonacci series ** @ author yinger */ Public Class Nineoj_t4 { Public Static Void Main (string [] ARGs) {commandid = New Using (system. In ); Int N; While (Records. hasnextint () {n = Response. nextint (); system. Out . Println (FAB (n ));}} Public Static Biginteger FAB ( Int N ){ If (N = 0 ){ Return Biginteger. Zero ;} Else If (N = 1 ){ Return Biginteger. One;} biginteger result = Biginteger. Zero; biginteger num1 = Biginteger. One; biginteger num2 = Biginteger. One; For ( Int I = 1 ; I <n; I ++ ) {Result = Num2.add (num1); num1 = Num2; num2 = Result ;} Return Result ;}}