Pagini recente » Cod sursa (job #660223) | Cod sursa (job #502620) | Cod sursa (job #894418) | Cod sursa (job #2494032) | Cod sursa (job #643117)
Cod sursa(job #643117)
#include<cstdio>
#define MOD 666013
#define ll long long
using namespace std;
class matrice{
public: ll a, b, c, d;
matrice (){
a = b = c = d = 0;
}
matrice (ll a1, ll b1, ll c1, ll d1){
this->a = a1;
this->b = b1;
this->c = c1;
this->d = d1;
}
matrice operator * (matrice other){
matrice m;
m.a = (this->a * other.a + this->b * other.c) % MOD;
m.b = (this->a * other.b + this->b * other.d) % MOD;
m.c = (this->c * other.a + this->d * other.c) % MOD;
m.d = (this->c * other.b + this->d * other.d) % MOD;
return m;
}
};
matrice X (0, 1, 1, 1);
matrice Pow(int p){
if (p == 1) return X;
if (p % 2 == 1) return X * Pow(p-1);
return Pow(p/2) * Pow(p/2);
}
int main(){
int k;
freopen ("kfib.in", "r", stdin), freopen("kfib.out", "w" , stdout);
scanf ("%d", &k);
matrice M = Pow(k - 1);
printf("%lld\n", M.d);
return 0;
}