Pagini recente » Cod sursa (job #510032) | Cod sursa (job #2078544) | Cod sursa (job #2432848) | Cod sursa (job #2884732) | Cod sursa (job #3183056)
#include <fstream>
using namespace std;
ifstream cin("kfib.in");
ofstream cout("kfib.out");
const int MOD = 666013;
const char same[] = "same";
class matrice{
public:
long long mat[2][2];
matrice(){
this->mat[0][0] = 0;
this->mat[0][1] = 1;
this->mat[1][0] = 1;
this->mat[1][1] = 1;
}
matrice(const int &x1, const int &x2){
this->mat[0][0] = x1;
this->mat[0][1] = x2;
this->mat[1][0] = 0;
this->mat[1][1] = 0;
}
matrice(const char *c){
this->mat[0][0] = 1;
this->mat[0][1] = 0;
this->mat[1][0] = 0;
this->mat[1][1] = 1;
}
matrice operator *(const matrice &other)const{
matrice ans;
ans.mat[0][0] = (this->mat[0][0] * other.mat[0][0] + this->mat[0][1] * other.mat[1][0]) % MOD;
ans.mat[0][1] = (this->mat[0][0] * other.mat[0][1] + this->mat[0][1] * other.mat[1][1]) % MOD;
ans.mat[1][0] = (this->mat[1][0] * other.mat[0][0] + this->mat[1][1] * other.mat[1][0]) % MOD;
ans.mat[1][1] = (this->mat[1][0] * other.mat[0][1] + this->mat[1][1] * other.mat[1][1]) % MOD;
return ans;
}
};
matrice lgput(matrice matr, int pow){
matrice rez(same);
while(pow){
if(pow % 2 == 1)
rez = (rez * matr);
matr = (matr * matr);
pow /= 2;
}
return rez;
}
matrice matrix, start(1, 1);
int main() {
int x;
cin >> x;
matrix = lgput(matrix, x - 1);
start = start * matrix;
cout << start.mat[0][0];
return 0;
}