Computer Programming Contest Preparation

ToolBox - Source for: 4/495/a495.java



/home/toolbox/public_html/solutions/4/495/a495.java
    1 import java.util.Scanner;
    2 import java.math.BigInteger;
    3 
    4 class a495
    5 {
    6     public static void main(String[] args)
    7     {
    8         BigInteger[] fib;
    9         fib = new BigInteger[5001];
   10 
   11         fib[0] = BigInteger.valueOf(0);
   12         fib[1] = BigInteger.valueOf(1);
   13         for (int i = 2; i<5001; i++)
   14             {
   15                 fib[i] = fib[i-1].add(fib[i-2]);
   16             }
   17 
   18         Scanner sc = new Scanner(System.in);
   19         while (sc.hasNext())
   20             {
   21                 int t = sc.nextInt();
   22                 System.out.print("The Fibonacci number for ");
   23                 System.out.print(t);
   24                 System.out.print(" is ");
   25                 System.out.println(fib[t]);
   26             }
   27     }
   28 }
   29