-
nth fibonacci
can someone explain to me how this program calculates nth fibonacci number? I scribbled for 2 hours now and stuck :)
hints greatly appreciated.
Code:
int f (unsigned int n) {
int x = 0, y = 1, a = 1, b = 0, t;
for (;;) {
if (n & 1) {
t = a;
a = a * x + b * y;
b = t * y + b * (x + y);
}
n >>= 1;
if (n == 0) return b;
t = x;
x = x * x + y * y;
y = t * y + y * (t + y);
}
}
Thanks.
-
Looks like nobody has a clue. :)
To the hints,
checks to see if n is odd number. And
is like n /= 2;
So it goes.