Hat's Fibonacci
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 int n,i; 11 BigInteger a1,a2,a3,a4,a5; 12 Scanner cin=new Scanner(System.in); 13 while(cin.hasNext()) 14 { 15 a1=BigInteger.valueOf(1); 16 a2=BigInteger.valueOf(1); 17 a3=BigInteger.valueOf(1); 18 a4=BigInteger.valueOf(1); 19 a5=BigInteger.valueOf(1); 20 n=cin.nextInt(); 21 for(i=5;i<=n;i++) 22 { 23 a5=a4.add(a3.add(a2.add(a1))); 24 a1=a2; 25 a2=a3; 26 a3=a4; 27 a4=a5; 28 } 29 System.out.println(a5); 30 } 31 } 32 }
//也可以用数组,初始化可以省一些。