Cod sursa(job #1921083)

Utilizator stefan_gheorgheGheorghe Stefan stefan_gheorghe Data 10 martie 2017 11:18:11
Problema Al k-lea termen Fibonacci Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("kfib.in");
ofstream g("kfib.out");
int k,m=666013;
struct ccc{long long int a,b,c,d;}x, y;
void mul(ccc &v, ccc w){
ccc aux=v;
 v.a=((aux.a*w.a)%m+(aux.b*w.c)%m)%m;
 v.b=((aux.a*w.b)%m+(aux.b*w.d)%m)%m;
 v.c=((aux.c*w.a)%m+(aux.d*w.c)%m)%m;
 v.d=((aux.c*w.b)%m+(aux.d*w.d)%m)%m;
}
void put(int p){
  while(p!=0)
  {
      if(p%2==0)
          mul(x,x),p=p/2;
      if(p%2==1)
          mul(y,x),p--;
  }
}
int main()
{
    f>>k;
    y.a=0,y.b=1,y.c=1,y.d=1;
    x.a=0,x.b=1,x.c=1,x.d=1;
    put(k-2);
    g<<(y.a+y.c)%m;

return 0;
}