Pagini recente » Cod sursa (job #1409296) | Cod sursa (job #2395187) | Cod sursa (job #912224) | Cod sursa (job #1955503) | Cod sursa (job #1429375)
#include<iostream>
#include<fstream>
const int mod=666013;
using namespace std;
int n;
struct matrice
{
int a,b,c,d;
} z;
void produs(matrice &x, matrice y);
void putere(matrice &x, int p);
int main()
{
ifstream in("kfib.in");
ofstream out("kfib.out");
in>>n;
z.a=0,z.b=z.c=z.d=1;
putere(z,3);
cout<<z.a<<' '<<z.b<<'\n'<<z.c<<' '<<z.d;
}
void putere(matrice &x, int p)
{
matrice N;
N.a=N.d=1;
N.b=N.c=0;
while(p>1)
{
if(p&1) produs(N,x);
produs(x,x);
p/=2;
}
produs(x,N);
}
void produs(matrice &x, matrice y)
{
int aa,bb,cc,dd;
aa=x.a*y.a+x.b*y.b;
bb=x.a*y.b+x.b*y.d;
cc=x.c*y.a+x.d*y.c;
dd=x.c*y.b+x.d*y.d;
x.a=aa%mod;
x.b=bb%mod;
x.c=cc%mod;
x.d=dd%mod;
}