Cod sursa(job #2244166)

Utilizator TeodorAxinteAxinte Teodor TeodorAxinte Data 22 septembrie 2018 12:48:39
Problema Al k-lea termen Fibonacci Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include <fstream>

using namespace std;
ifstream f("kfib.in");
ofstream g("kfib.out");
typedef long long Int;
const Int MOD = 666013LL;
struct triplet
{
    Int a,b,c;
    triplet(Int x,Int y,Int z):a(x),b(y),c(z){};
};
triplet operator*(triplet A,triplet B)
{
    return triplet( (A.a*B.a+A.b*B.b)%MOD , (A.a*B.b+A.b*B.c)%MOD , (A.b*B.b+A.c*B.c)%MOD );
}
triplet operator^(triplet B, Int e)
{
    if(e==0)return triplet(1,0,1);
    triplet R = B ^ (e/2);
    R=R*R;
    if(e%2)R=R*B;
    return R;
}
int main()
{
    Int k;
    f>>k;
    g<<(triplet(1,1,0)^k).b;
    return 0;
}