java大数 斐波那契数列

时间:2023-03-08 17:42:16

java大数做斐波那契数列:

 思路:1.

     
2.可以用数组存着

import java.math.BigInteger;
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		while(cin.hasNext()){//remermber
			BigInteger num1=cin.nextBigInteger();
			BigInteger num2=cin.nextBigInteger();
			BigInteger num3=cin.nextBigInteger();
			BigInteger num4 = null;
			for(int i=4;i<=100;++i){
				num4=num1.add(num2).add(num3);
				if(i%3==1){
					num1=num4;
				}else if(i%3==2){
					num2=num4;
				}else{
					num3=num4;
				}
			}
			System.out.println(num4);
		}
	}

}