Pages

1/19/2014

UVA 10579 Fibonacci Numbers Solution

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

class Main {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
BigInteger [] bg = new BigInteger[5001];

bg[0] = BigInteger.ZERO;
bg[1] = BigInteger.ONE;
for (int i=2; i<5001; i++) bg[i] = bg[i-1].add(bg[i-2]);

//System.out.println(bg[5000].toString(10).length());
Scanner sc = new Scanner(System.in);
while(sc.hasNext())
{
int i = sc.nextInt();
System.out.println( bg[i]);
}
}

}

No comments :

Post a Comment