2016"百度之星" - 资格赛(Astar Round1) Problem B

规律题,斐波那契数列,数据有毒,0的时候输出换行。会爆longlong,写个大数模板或者Java搞。

import java.io.BufferedInputStream;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    

    public static void main(String[] args) {
        Scanner sc = new Scanner (new BufferedInputStream(System.in));
        
        BigInteger[] fib=new BigInteger [300];
        fib[0]=BigInteger.ZERO;
        fib[1]=BigInteger.ONE;
        for(int i=2;i<=201;i++)
        {
            fib[i]=fib[i-1].add(fib[i-2]);
        }
            
        while (sc.hasNext()){
            int n = sc.nextInt(); 
            if(n==0)
            {
                System.out.println();
            }
            else System.out.println(fib[n+1].toString());
        }
    }
} 

 

posted @ 2016-05-15 09:55  Fighting_Heart  阅读(130)  评论(0编辑  收藏  举报