Cod sursa(job #2845767)

Utilizator DooMeDCristian Alexutan DooMeD Data 8 februarie 2022 12:04:14
Problema Al k-lea termen Fibonacci Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.8 kb
#include <bits/stdc++.h>
using namespace std;

int M[2][2] = {{0,1},
               {1,1}};

int F[2][2] = {{0,1},
               {1,1}};

void multiply(int A[][2], int B[][2]) {
    int temp[2][2];
    for(int i=0; i<2; i++)
        for(int j=0; j<2; j++) {
            int rez = 0;
            for(int l=0; l<2; l++)
                rez = rez + A[i][l] * B[l][j];
            temp[i][j] = rez;
        }
    for(int i=0; i<2; i++, cout << "\n")
        for(int j=0; j<2; j++)
            cout << temp[i][j] << " ";
}

void exp(int n) {
    while(n) {
        if(n%2) multiply(F,M);
        n /= 2;
        multiply(M,M);
    }
}

int main () {
    ifstream f ("kfib.in");
    ofstream g ("kfib.out");

    multiply(M,F);

    int n; f >> n;
    //exp(n-1);
    return 0;
}