java高精度秒解
查看原帖
java高精度秒解
426122
NewYang2020楼主2020/11/21 20:14
import java.math.BigInteger;
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        BigInteger b1 = new BigInteger("1");
        BigInteger b2 = new BigInteger("1");
        BigInteger b3 = new BigInteger("2");
        int N;
        Scanner in = new Scanner(System.in);
        N = in.nextInt();
        if(N == 1)
            System.out.println(1);
        else if (N == 0)
            System.out.println(0);
        else if(N == 2)
            System.out.println(2);
        else if(N == 3)
            System.out.println(3);
        else{
            for(int i = 1; i < N; i++){
                b3 = b1.add(b2);
                b1 = b2;
                b2 = b3;
            }
            System.out.println(b3);
        }
    }
}

注意N=0时的情况

2020/11/21 20:14
加载中...