Cod sursa(job #3358396)
| Utilizator | Data | 16 iunie 2026 16:55:52 | |
|---|---|---|---|
| Problema | Al k-lea termen Fibonacci | Scor | 0 |
| Compilator | c-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#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));
}
