Pagini recente » Cod sursa (job #3202542) | Cod sursa (job #2687682) | Cod sursa (job #745926) | Cod sursa (job #456984) | Cod sursa (job #2907438)
#include <bits/stdc++.h>
using namespace std;
const int MOD = 666013;
#define int long long
ifstream fin( "kfib.in" );
ofstream fout( "kfib.out" );
void product( int a[2][2], int b[2][2] ) {
int aux[2][2];
int i, j, k;
for( i = 0; i < 2; i++ ) {
for( j = 0; j < 2; j++ ) {
aux[i][j] = 0;
for( k = 0; k < 2; k++ )
aux[i][j] = ( aux[i][j] + a[i][k] * b[k][j] ) % MOD;
}
}
for( i = 0; i < 2; i++ ) {
for( j = 0; j < 2; j++ )
a[i][j] = aux[i][j];
}
}
int rez[2][2] = { { 0, 1 }, { 1, 1 } };
void lgput( int a[2][2], int put ) {
while( put ) {
if( put % 2 == 1 )
product( rez, a );
product( a, a );
put /= 2;
}
}
int mat[2][2] = { { 0, 1 }, { 1, 1 } };
signed main() {
int n;
fin >> n;
lgput( mat, n - 1 );
fout << rez[0][1];
return 0;
}