hdu 1250 Hat's Fibonacci(java,简单,大数)
java做大数的题,真的是神器,来一道,秒一道~~~
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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(); //关闭输入文件 } }
一道又一道,好高兴!