Pagini recente » Cod sursa (job #530231) | Cod sursa (job #742240) | Cod sursa (job #2363215) | Cod sursa (job #2151274) | Cod sursa (job #1198937)
#include<fstream>
using namespace std;
struct mat
{
long long a,b,c,d;
};
ifstream fin("kfib.in");
ofstream fout("kfib.out");
const int modulo=666013;
int k;
mat w,z,aux,h;
inline mat Inmulteste(const mat e,const mat f)
{
aux.a=(1LL*e.a*f.a+1LL*e.b*f.c)%modulo;
aux.b=(1LL*e.a*f.b+1LL*e.b*f.d)%modulo;
aux.c=(1LL*e.c*f.a+1LL*e.d*f.c)%modulo;
aux.d=(1LL*e.c*f.b+1LL*e.d*f.d)%modulo;
return aux;
}
inline mat Log(int x)
{
if (x==1) return w;
else if (x&1) return Inmulteste(w,Log(x-1));
else
{
h=Log(x>>1);
return Inmulteste(h,h);
}
}
int main()
{
fin>>k;
w.a=0;
w.b=w.c=w.d=1;
if (k>=2)
{
z=Log(k-1);
fout<<z.d;
}
else if (k==1) fout<<"1";
else fout<<"0";
fout<<"\n";
return 0;
}