Pagini recente » Cod sursa (job #2673040) | Cod sursa (job #2744543) | Cod sursa (job #2716640) | Cod sursa (job #1980149) | Cod sursa (job #3195983)
#include <bits/stdc++.h>
#define mod 666013
using namespace std;
ifstream fin("kfib.in");
ofstream fout("kfib.out");
struct mat2x2{
int m[2][2];
};
void init(mat2x2 &m1){
m1.m[0][0] = 0;
m1.m[0][1] = m1.m[1][0] = m1.m[1][1] = 1;
}
void mult(mat2x2 &m1, mat2x2 m2){
mat2x2 rez;
rez.m[0][0] = (1LL * m1.m[0][0] * m2.m[0][0] + 1LL * m1.m[0][1] * m2.m[1][0]) % mod;
rez.m[1][0] = (1LL * m1.m[0][0] * m2.m[0][1] + 1LL * m1.m[0][1] * m2.m[1][1]) % mod;
rez.m[0][1] = (1LL * m1.m[1][0] * m2.m[0][0] + 1LL * m1.m[1][1] * m2.m[1][0]) % mod;
rez.m[1][1] = (1LL * m1.m[1][0] * m2.m[0][1] + 1LL * m1.m[1][1] * m2.m[1][1]) % mod;
m1.m[0][0] = rez.m[0][0];
m1.m[0][1] = rez.m[0][1];
m1.m[1][0] = rez.m[1][0];
m1.m[1][1] = rez.m[1][1];
}
int exp(int p){
mat2x2 mat,rez;
init(mat);
init(rez);
while(p){
if(p & 1) mult(rez, mat);
mult(mat, mat);
p >>= 1;
}
return (rez.m[0][0] + rez.m[1][0] + mod) % mod;
}
int main()
{
int n;
fin >> n;
fout << exp(n - 2);
return 0;
}