Pagini recente » Cod sursa (job #3260902) | Cod sursa (job #1243999)
#include <cstdio>
#include <cstring>
using namespace std;
class matrice{
public:
int m[2][2];
matrice(){
memset(m,0,sizeof(m));
}
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.m[i][j]=(c.m[i][j]+((1LL*m[i][k]*b.m[k][j])%666013))%666013;
*this=c;
}
};
void pow(matrice a,int b){
matrice p;
p.m[0][0]=1;
p.m[1][1]=1;
for(;b;b>>=1){
if(b&1) p*=a;
a*=a;
}
printf("%d",p.m[0][1]);
}
int main(){
freopen("kfib.in","r",stdin);
freopen("kfib.out","w",stdout);
int n;
scanf("%d",&n);
matrice a;
a.m[0][0]=1;
a.m[1][0]=1;
a.m[0][1]=1;
pow(a,n);
return 0;
}