Pagini recente » Cod sursa (job #2532727) | Cod sursa (job #1047988) | Cod sursa (job #2115657) | Cod sursa (job #704093) | Cod sursa (job #1415131)
#include<fstream>
using namespace std;
ifstream in("kfib.in");
ofstream out("kfib.out");
const int MOD = 666013;
typedef int MAT[2][2];
void multiply(MAT& B,MAT A)
{
MAT C;
for(int i = 0 ; i < 2 ; ++i)
for(int j = 0 ; j < 2 ; ++j)
C[i][j] = 0;
for(int i = 0 ; i < 2 ; ++i)
for(int j = 0 ; j < 2 ; ++j){
for(int k = 0 ; k < 2 ; ++k)
C[i][j] = (C[i][j] + 1LL* A[i][k] * B[k][j])%MOD;
}
for(int i = 0 ; i < 2 ; ++i)
for(int j = 0 ; j < 2 ; ++j)
B[i][j] = C[i][j];
}
int putere(int exp)
{
MAT R,P;
R[0][0] = P[0][0] = 0;
R[0][1] = P[0][1] = 1;
R[1][0] = P[1][0] = 1;
R[1][1] = P[1][1] = 1;
while(exp){
if(exp%2){
multiply(R,P);
--exp;
}
multiply(P,P);
exp /= 2;
}
return R[0][0];
}
int main()
{
int k;
in>>k;
out<<putere(k);
return 0;
}