Pagini recente » Cod sursa (job #841286) | Cod sursa (job #2508315) | Cod sursa (job #1149551) | Cod sursa (job #1843108) | Cod sursa (job #1366926)
#include <vector>
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
ifstream fin("kfib.in");
ofstream fout("kfib.out");
const int mod = 666013;
int k;
inline 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)
for(int k = 0 ; k < 2 ; ++ k)
a[i][j] = (a[i][j] + 1LL * b[i][k] * c[k][j]) % mod;
}
inline void lgput(int p) {
int ans[2][2] = {
{1, 0},
{0, 1}
};
int z[2][2] = {
{0, 1},
{1, 1}
};
int aux[2][2];
for( ; p ; p >>= 1) {
if(p & 1) {
memset(aux, 0, sizeof(aux));
multiply(aux, ans, z);
memcpy(ans, aux, sizeof(ans));
}
memset(aux, 0, sizeof(aux));
multiply(aux, z, z);
memcpy(z, aux, sizeof(aux));
}
fout << ans[1][1] << '\n';
}
int main() {
fin >> k;
lgput(k - 1);
}