Pagini recente » Cod sursa (job #463656) | Cod sursa (job #2524930) | Cod sursa (job #2059388) | Cod sursa (job #1074034) | Cod sursa (job #1836071)
#include <iostream>
#include <cstdint>
#include <cmath>
#include <stdio.h>
using namespace std;
void rezultat(int** z){
cout << "rezultat:";
cout << (1*z[1][2] + 2*z[2][2]) % 666013;
}
int ** inmultire_matrici(int **z, int **x){
int** A = (int**)malloc(2*sizeof(int*));
A[1][1] = (z[1][1]*x[1][1]% 666013 + z[1][2]*x[2][1]% 666013) % 666013;
A[1][2] = (z[1][1]*x[1][2]% 666013 + z[1][2]*x[2][2]% 666013) % 666013;
A[2][1] = (z[2][1]*x[1][1]% 666013 + z[2][2]*x[2][1]% 666013) % 666013;
A[2][2] = (z[2][1]*x[1][2]% 666013 + z[2][2]*x[2][2]% 666013) % 666013;
return A;
}
int ** exponentiere(int **z, int P){
int** A = (int**)malloc(2*sizeof(int*));
if(P == 1)
rezultat(z);
if(P%2 == 0){
A = inmultire_matrici(z, z);
return exponentiere(A, P/2);
}
else
{
A = exponentiere(z, (P-1)/2);
return inmultire_matrici(z, A);
}
}
int main(){
//freopen("lgput.in", "r", stdin);
//freopen("lgput.out", "w", stdout);
int** z = (int**)malloc(3*sizeof(int*));
long long N;
cin >> N;
z[1][1] = 0;
z[1][2] = 1;
z[2][1] = 1;
z[2][2] = 1;
// exponentiere(z, N-1);
// cout << exponentiere(N, P) % 1999999973;
return 0;
}