10579 Fibonacci Numbers

code:

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

/**
 * Created by Zaki on 6/11/2017.
 */
public class Uva_Fibonacci {
    public static void main(String[] args)
    {
        Scanner input=new Scanner(System.in);
        int n;
        while(input.hasNext()){
            n=input.nextInt();
            BigInteger a = new BigInteger("1");
            BigInteger b= new BigInteger("1");
            BigInteger sum=new BigInteger("0");
            while(n>=3) {
                sum = a.add(b);
                b = a;
                a = sum;
                n--;
            }
        System.out.println(sum);
        }
    }
}

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published.