Pagini recente » Cod sursa (job #2106900) | Borderou de evaluare (job #888906) | Cod sursa (job #2791025) | Cod sursa (job #2821614) | Cod sursa (job #1243245)
#include<cstdio>
#include<cstring>
using namespace std;
const int mod=666013;
class matrice
{
public:
int mat[2][2];
matrice()
{
memset(mat,0,sizeof(mat));
}
void operator *=(const matrice &other)
{
matrice c;
for(int i=0;i<2;++i)
for(int j=0;j<2;++j)
for(int k=0;k<2;k++)
c.mat[i][j]=(c.mat[i][j]+((long long)mat[i][k]*other.mat[k][j])%mod)%mod;
*this=c;
}
};
matrice pow(matrice a,int b)
{
matrice p;
p.mat[0][0]=p.mat[1][1]=1;
for( ;b;b>>=1)
{
if(b&1)
p*=a;
a*=a;
}
return p;
}
int main()
{
freopen("kfib.in","r",stdin);
freopen("kfib.out","w",stdout);
matrice a;
a.mat[0][0]=a.mat[1][0]=a.mat[0][1]=1;
int k;
scanf("%d",&k);
a=pow(a,k-1);
printf("%d\n",a.mat[0][0]);
return 0;
}