Pagini recente » Cod sursa (job #3330407) | Cod sursa (job #1789458) | Cod sursa (job #1789412) | Cod sursa (job #3358487) | Cod sursa (job #3358396)
#include <stdio.h>
#include <string.h>
int Z[2][2], N, M[2];
void multMZ(){
int a = M[0]*Z[0][0] + M[1]*Z[0][1];
int b = M[0]*Z[1][0] + M[1]*Z[1][1];
M[0] = a;
M[1] = b;
}
int fib(int N, int i){
multMZ();
if(i != N)
return fib(N, i+1);
return M[1];
}
int main()
{
freopen("kfib.in", "r", stdin);
freopen("kfib.out", "w", stdout);
Z[0][0] = 0;
Z[0][1] = 1;
Z[1][1] = 1;
Z[1][0] = 1;
M[0] = 0; M[1] = 1;
scanf("%d", &N);
printf("%d", fib(N, 2));
}