Pagini recente » Cod sursa (job #1165882) | Cod sursa (job #2836354) | Cod sursa (job #1475936) | Cod sursa (job #1457421) | Cod sursa (job #1243120)
#include<cstdio>
#include<cstring>
#include<algorithm>
class matrice
{
public:
int x[2][2];
matrice()
{
memset(x,0,sizeof(x));
}
void operator *=(const matrice&b)
{
matrice c;
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
for(int k=0;k<2;k++)
{
c.x[i][j]=(c.x[i][j]+((1LL*x[i][k]*b.x[k][j])%666013))%666013;
}
}
}
*this=c;
}
};
matrice power(matrice a,int b)
{
matrice p;
p.x[0][0]=1;
p.x[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.x[0][0]=1;
a.x[0][1]=1;
a.x[1][0]=1;
int k;
scanf("%d",&k);
a=power(a,k-1);
printf("%d",a.x[0][0]);
return 0;
}