Here's the code I wrote for finding the n-th Fibonacci number:
unsigned long long fib(int n)
{
unsigned long long u = 1, v = 1, t;
for(int i=2; i<=n; i++)
{
t = u + v;
u = v;
v = t;
}
return v;
}
While the algorithm runs pretty quickly, the output starts to freak out when n>93. I think/know it's because of the unsigned long long's 64bit size. I'm new to C++ but are there ways of getting around this so I can get the answer of something like fib(9999)?
Thanks