static int fibonacci(int n)
{
int[,] fib= {{1,1},{1,0}};
int[,] blu= {{1,0},{0,1}};
int a, b, c, d;
while(n > 0)
{
if(n % 2 != 0)
{
a = blu[0, 0] * fib[0, 0] + blu[0, 1] * fib[1, 0];
b = blu[0, 0] * fib[0, 1] + blu[0, 1] * fib[1, 1];
c = blu[1, 0] * fib[0, 0] + blu[1, 1] * fib[1, 0];
d = blu[1, 0] * fib[0, 1] + blu[1, 1] * fib[1, 1];
blu[0, 0] = a;
blu[0, 1] = b;
blu[1, 0] = c;
blu[1, 1] = d;
}
a = fib[0, 0] * fib[0, 0] + fib[0, 1] * fib[1, 0];
b = fib[0, 0] * fib[0, 1] + fib[0, 1] * fib[1, 1];
c = fib[1, 0] * fib[0, 0] + fib[1, 1] * fib[1, 0];
d = fib[1, 0] * fib[0, 1] + fib[1, 1] * fib[1, 1];
fib[0, 0] = a;
fib[0, 1] = b;
fib[1, 0] = c;
fib[1, 1] = d;
n/=2;
}
return (blu[0,1]);
}