UVa 495 - Fibonacci Freeze

This problem requires bignum. Initially i calculated the fibonacci numbers from the begining ie. for n=5, i used to start from 1 ,2 ,3, 5  , then for n=6, i again started from 1 2 3 5 etc, I got TLE.

i generated 5000 fibonacci numbers and then stored them in a 2-d array once. Now for every n i printed the value and got accepted. Fibonacci (5000) is larger than 1000 digits.