Pagini recente » Cod sursa (job #1310069) | Cod sursa (job #1336039) | Cod sursa (job #293857) | Cod sursa (job #2562574) | Cod sursa (job #2023371)
#include <cstdio>
#define mod 666013
using namespace std;
int m[2][2]={{1, 1}, {1, 0}};
int mat[2][2]={{1, 1}, {1, 0}};
int matrice[2][2]={{1, 1}, {1, 0}};
int k, a, b;
void inmultire(int m1[2][2], int m2[2][2], int rez[2][2])
{
rez[0][0]=((1LL*m1[0][0]*m2[0][0])%mod+(1LL*m1[0][1]*m2[1][0])%mod)%mod;
rez[0][1]=((1LL*m1[0][0]*m2[0][1])%mod+(1LL*m1[0][1]*m2[1][1])%mod)%mod;
rez[1][0]=((1LL*m1[1][0]*m2[0][0])%mod+(1LL*m1[1][1]*m2[1][0])%mod)%mod;
rez[1][1]=((1LL*m1[1][0]*m2[0][1])%mod+(1LL*m1[1][1]*m2[1][1])%mod)%mod;
}
void fibonacci(int k)
{
if(k==1)
return;
if(k%2==0)
{
fibonacci(k/2);
inmultire(mat, mat, m);
mat[0][0]=m[0][0];
mat[0][1]=m[0][1];
mat[1][0]=m[1][0];
mat[1][1]=m[1][1];
}
else
{
fibonacci(k-1);
inmultire(mat, matrice, m);
mat[0][0]=m[0][0];
mat[0][1]=m[0][1];
mat[1][0]=m[1][0];
mat[1][1]=m[1][1];
}
// while(k!=1)
// {
// inmultire(mat, matrice, m);
// mat[0][0]=m[0][0];
// mat[0][1]=m[0][1];
// mat[1][0]=m[1][0];
// mat[1][1]=m[1][1];
// k--;
// }
}
int main()
{
freopen("kfib.in", "r", stdin);
freopen("kfib.out", "w", stdout);
scanf("%d", &k);
fibonacci(k-1);
printf("%d", m[0][0]);
return 0;
}