Accepted solution

UVA 495 - Fibonacci Freeze

Open original problem
Source code

import java.math.BigInteger;

import java.util.Scanner;

public class Main {

    public static void main(String[] args)

   {

        BigInteger fib[] = new BigInteger[5100];

        Scanner sc = new Scanner(System.in);

        int n;

        fib[0] = BigInteger.ZERO;

        fib[1] = BigInteger.ONE;

        for (int i = 2; i <= 5000; i++)

        {

            fib[i] = fib[i - 1].add(fib[i - 2]);

        }

     

   

        while (sc.hasNext())

          {

            n = sc.nextInt();

            System.out.format("The Fibonacci number for %d is %s
", n, fib[n].toString());

         }

   

    }

}
Join the discussion

Add your comment