Cod sursa(job #1541770)

Utilizator GrandmasterSoucup Bogdan Grandmaster Data 4 decembrie 2015 15:47:43
Problema Al k-lea termen Fibonacci Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.08 kb
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>
#include <cstring>
#include <map>
#include <iomanip>
#include <time.h>
#include <stdio.h>
//#include <iostream>
using namespace std;
ifstream cin("kfib.in");
ofstream cout("kfib.out");
int MOD = 666013;
struct matrice{
    unsigned long long a, b, c, d;

};
matrice operator *(matrice x, matrice y)
{
    matrice z;
    z.a = (x.a * y.a + x.b * y.c) % MOD;
    z.b = (x.a * y.b + x.b * y.d) % MOD;
    z.c = (x.c * y.a + x.d * y.c) % MOD;
    z.d = (x.c * y.b + x.d * y.d) % MOD;
    return z;
}
matrice x, y, z, nullm, cop;
matrice putere(matrice x, int e, matrice nullm)
{
    if(e == 0)
        return nullm;
    if(e % 2 == 0){
        matrice gov = putere(x, e / 2, nullm);
        return gov * gov;
    }
    else
        return x * putere(x, e - 1, nullm);
}
int main(){
    int v;
    cin >> v;
    x.a = 0;x.b = 1;
    x.c = 1;x.d = 1;
    nullm.a = 1;nullm.b = 0;
    nullm.c = 0;nullm.d = 1;
    cop = putere(x, v, nullm);
    cout << cop.b;
    return 0;
}