UVA 495 - Fibonacci Freeze

UVA Sep 1, 2020

Problem PDF

Solution:

import java.io.*;
import java.util.Scanner;
import java.util.ArrayList;
import java.math.BigInteger;

public class Main
{
    public static void main(String [] args0)
    {

        BigInteger [] fibs = new BigInteger [5001];
        Scanner in = new Scanner(System.in);
        fibs[0] = BigInteger.ZERO;
        fibs[1] = BigInteger.ONE;
        fibs[2] = BigInteger.ONE;
        for(int i = 3; i < 5001; i++)
        {
            fibs[i] = fibs[i-1].add(fibs[i-2]);
        }
        while( in.hasNextInt() ){
            int n = in.nextInt();
            System.out.println("The Fibonacci number for " + n + " is " + fibs[n] );
        }

    }


}
https://github.com/Shipu/OnlineJudgeProblemSolutionWithCPlusPlus/tree/master/uva/495/Main.java

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.