Pagini recente » Cod sursa (job #1594476) | Cod sursa (job #1121245) | Autentificare | Cod sursa (job #1752625) | Cod sursa (job #2022889)
#include <cstdio>
#define mod 666013
using namespace std;
int m[2][2]={{0, 1}, {1, 1}};
int mat[2][2]={{0, 1}, {1, 1}};
int matrice[2][2]={{0, 1}, {1, 1}};
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;
// for(int i=0;i<2;i++)
// {
// for(int j=0;j<2;j++)
// printf("%d ", m[i][j]);
// printf("\n");
// }
// printf("\n");
}
void fibonacci(int k)
{
// if(k==0)
// return;
// printf("%d\n", k);
// if(k%2==0)
// {
// 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];
// fibonacci(k/2);
// }
// else
// {
// fibonacci(k-1);
// inmultire(mat, matrice, m);
// }
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[1][1]);
return 0;
}