hdu 1250 Hat's Fibonacci(java,简单,大数)

题目

 

java做大数的题,真的是神器,来一道,秒一道~~~

 

import java.io.*;
import java.util.*;
import java.math.*;

public class Main {

    /**
     * @xqq
     */
    public BigInteger an(int n) {
        BigInteger e;
        BigInteger a = BigInteger.valueOf(1);
        BigInteger b = BigInteger.valueOf(1);
        BigInteger c = BigInteger.ONE;
        BigInteger d = BigInteger.ONE;
        
        for(int i = 1; i < n; i++) {
            e = a.add(b.add(c.add(d)));
            a = b;
            b = c;
            c = d;
            d = e;
        }
        return a;
    }
    public static void main(String[] args)    throws Exception {
        // 定义并打开输入文件
        Scanner cin = new Scanner(System.in);
        
        Main e = new Main();
        int n;
        
        while(cin.hasNext()) {
            n = cin.nextInt();    
            System.out.println(e.an(n));
        }
        
        cin.close();  //关闭输入文件
    }
}
View Code

 

 

 

 

posted @ 2014-05-01 16:27  laiba2004  Views(106)  Comments(0Edit  收藏  举报