Pagini recente » Cod sursa (job #2806028) | Cod sursa (job #3290857) | Cod sursa (job #1323430) | Cod sursa (job #1441732) | Cod sursa (job #2875681)
#include <bits/stdc++.h>
#define mod 666013
using namespace std;
ifstream f("kfib.in");
ofstream g ("kfib.out");
long long k;
struct mat {
long long M[2][2];
};
mat mati={
0,1,
1,1
};
mat prod (mat A,mat B)
{
mat a;
a.M[0][0]=(A.M[0][0]*B.M[0][0]+A.M[0][1]*B.M[1][0])%mod;
a.M[0][1]=(A.M[0][0]*B.M[0][1]+A.M[0][1]*B.M[1][1])%mod;
a.M[1][0]=(A.M[1][0]*B.M[0][0]+A.M[1][1]*B.M[1][0])%mod;
a.M[1][1]=(A.M[1][0]*B.M[0][1]+A.M[1][1]*B.M[1][1])%mod;
return a;
}
mat lgput(mat M,long long k)
{
if(k==1)
return M;
if(k%2==0)
return lgput(prod(M,M),k/2);
return prod(M,lgput(prod(M,M),k/2));
}
int main()
{
f>>k;
g<<lgput(mati,k).M[1][0];
return 0;
}