Cod sursa(job #2799446)

Utilizator AlexTacuTacu Alexandru AlexTacu Data 13 noiembrie 2021 10:51:30
Problema Al k-lea termen Fibonacci Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.82 kb
#include <bits/stdc++.h>
#define mod 666013

using namespace std;

ifstream in("kfib.in");
ofstream out("kfib.out");

int x;

void cit()
{
    in>>x;
}

void InmultireMat(int a[2][2],int b[2][2])
{
    int rez[2][2];
    for(int i=0;i<2;i++)
        for(int j=0;j<2;j++)
            rez[i][j]=(1ll*a[i][0]*b[0][j] + 1ll*a[i][1]*b[1][j]) % mod;
    for(int i=0;i<2;i++)
        for(int j=0;j<2;j++)
            a[i][j]=rez[i][j];
}

void lgput()
{
    int aux[2][2]=
       {
           {1,0},
           {0,1},
       };
    int ct[2][2]=
        {
           {0,1},
           {1,1},
       };
    while(x)
    {
        if(x%2)
            InmultireMat(aux,ct);
        InmultireMat(ct,ct);
        x/=2;
    }
    out<<aux[0][1];
}

int main()
{
    cit();
    lgput();
    return 0;
}