Pagini recente » Cod sursa (job #2937614) | Cod sursa (job #476957) | Cod sursa (job #304446) | Cod sursa (job #478568) | Cod sursa (job #3172364)
#include <bits/stdc++.h>
using namespace std;
#define INFILE "kfib.in"
#define OUTFILE "kfib.out"
typedef long long ll;
const int MOD = 666013;
ll n, x[2][2], y[2][2];
void mult(ll a[2][2], ll b[2][2]){
ll c[2][2];
memset(c, 0, sizeof c);
for(int i = 0; i < 2; ++i){
for(int j = 0; j < 2; ++j){
for(int k = 0; k < 2; ++k){
c[i][j] += a[i][k] * b[k][j];
c[i][j] %= MOD;
}
}
}
for(int i = 0; i < 2; ++i){
for(int j = 0; j < 2; ++j){
a[i][j] = c[i][j];
}
}
}
void solve(){
x[0][1] = x[1][0] = x[1][1] = y[0][0] = y[1][1] = 1;
cin >> n;
while(n){
if(n & 1){
mult(y, x);
}
mult(x, x);
n >>= 1;
}
cout << y[0][1] << '\n';
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
freopen(INFILE, "r", stdin);
freopen(OUTFILE, "w", stdout);
solve();
return 0;
}