大菲波数

 1 import java.lang.*;
 2 import java.util.*;
 3 import java.text.*;
 4 import java.math.*;
 5 import java.io.*;
 6 class Main
 7 {
 8     public static void main(String []args)
 9     {
10         Scanner cin=new Scanner(System.in);
11         BigInteger f[]=new BigInteger[3];
12         int i,n,m;
13         while(cin.hasNext())
14         {
15             m=cin.nextInt();
16             while(m-->0)
17             {
18                 n=cin.nextInt();
19                 f[0]=BigInteger.valueOf(1);
20                 f[1]=BigInteger.valueOf(1);
21                 f[2]=BigInteger.valueOf(1);
22                 if(n>2)
23                 {
24                     for(i=3;i<=n;i++)
25                     {
26                         f[2]=f[1].add(f[0]);
27                         f[0]=f[1];
28                         f[1]=f[2];
29                     }
30                     System.out.println(f[2]);
31                 }
32                 else System.out.println(1);
33             }
34         }
35     }
36 }
原文地址:https://www.cnblogs.com/hduacm/p/2650636.html