Pagini recente » Cod sursa (job #2567361) | Cod sursa (job #2686163) | Cod sursa (job #2527957) | Cod sursa (job #2500301) | Cod sursa (job #3209644)
#include <fstream>
using namespace std;
const int MOD = 666013;
const int Matrix_Size = 2;
typedef long long matrix[Matrix_Size][Matrix_Size];
matrix unitate = {{1, 0}, {0, 1}};
matrix recurenta_fib = {{1, 1}, {1, 0}};
void inmultire(matrix dest, matrix a, matrix b){
for(int lin = 0; lin < Matrix_Size; lin++){
for(int col = 0; col < Matrix_Size; col++){
dest[lin][col] = 0;
for(int i = 0; i < Matrix_Size; i++){
dest[lin][col] += a[lin][i] * b[i][col];
}
dest[lin][col] %= MOD;
}
}
}
void copiaza(matrix from, matrix to){
for(int i = 0; i < Matrix_Size; i++){
for(int j = 0; j < Matrix_Size; j++){
to[i][j] = from[i][j];
}
}
}
int lgput(matrix element, int exp){
matrix sol, aux;
copiaza(unitate, sol);
while(exp){
if(exp & 1){
inmultire(aux, element, sol);
copiaza(aux, sol);
}
inmultire(aux, element, element);
copiaza(aux, element);
exp >>= 1;
}
return sol[0][0];
}
int main(){
ifstream fin("kfib.in");
ofstream fout("kfib.out");
int n, first_element;
fin >> n;
first_element = 1;
fout << first_element * lgput(recurenta_fib, n - 1);
return 0;
}