Pagini recente » Cod sursa (job #2078690) | Statistici bogyor bogdan (bogyor) | Cod sursa (job #2821114) | Monitorul de evaluare | Cod sursa (job #1945840)
#include <fstream>
using namespace std;
ifstream in("kfib.in");
ofstream out("kfib.out");
const int mod = 666013;
int k;
int Sol[2][2] = {{0, 1}, {0, 0}};
int z[2][2];
void Multiply(int a[2][2], int b[2][2]){
int c[2][2];
for(int i = 0; i < 2; ++i){
for(int j = 0; j < 2; ++j){
c[i][j] = 0;
for(int l = 0; l < 2; ++l)
c[i][j] = (c[i][j] + 1LL * a[i][l] * b[l][j]) % mod;
}
}
for(int i = 0; i < 2; ++i){
for(int j = 0; j < 2; ++j)
a[i][j] = c[i][j];
}
}
void CoolAlgorithmWhichIdontKnowHowToTranslateInEnglish(int p){ // #numelePerfect
z[1][0] = z[0][1] = z[1][1] = 1;
while(p){
if(p % 2 == 1)
Multiply(Sol, z);
Multiply(z, z);
p /= 2;
}
}
void Print(){
out << Sol[0][1];
}
int main(){
in >> k;
CoolAlgorithmWhichIdontKnowHowToTranslateInEnglish(k - 1);
Print();
return 0;
}