Wednesday, August 19, 2015

UVa 10579 - Fibonacci Numbers

// UVa 10579 - Fibonacci Numbers

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

public class Main {

	public static void main(String[] args) {

		BigInteger[] f = new BigInteger[5000];
		f[1] = BigInteger.ONE;
		f[2] = BigInteger.ONE;
		for (int i = 3; i < 5000; i++)
			f[i] = f[i - 1].add(f[i - 2]);

		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNextInt()) {
			int n = scanner.nextInt();
			System.out.println(f[n]);
		}

	}

}

No comments:

Post a Comment