Pagini recente » agm-lagheta | Cod sursa (job #2701979) | Cod sursa (job #1341446) | Cod sursa (job #2014638) | Cod sursa (job #3290714)
#include <fstream>
using namespace std;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
const int modulo = 666013;
int mat[3][3];
int a, b, c;
void exponentiere_rapida(int mat[][3], int putere){
if (putere == 0){
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
mat[i][j] = (i == j);
}
}
} else if (putere % 2 == 0){
int aux[3][3];
exponentiere_rapida(mat, putere / 2);
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++) {
aux[i][j] = mat[i][j] % modulo;
mat[i][j] = 0;
}
}
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
for (int k = 0; k < 3; k++){
mat[i][j] = (1LL * mat[i][j] + 1LL * (1LL * aux[k][j] * aux[i][k])) % modulo;
}
}
}
} else {
int mat_normala[3][3] = {0};
int aux[3][3];
exponentiere_rapida(mat, putere - 1);
mat_normala[1][0] = mat_normala[2][1] = 1;
mat_normala[0][2] = c;
mat_normala[1][2] = b;
mat_normala[2][2] = a;
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++) {
aux[i][j] = mat[i][j] % modulo;
mat[i][j] = 0;
}
}
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
for (int k = 0; k < 3; k++){
mat[i][j] = (1LL * mat[i][j] + 1LL * (1LL * aux[k][j] * mat_normala[i][k])) % modulo;
}
}
}
}
}
int main() {
int teste;
fin >> teste;
for (int test = 1; test <= teste; test++){
int x, y, z, n;
// x iepuri ziua 1 y iepuri ziua 2 z iepuri
fin >> x >> y >> z >> a >> b >> c >> n;
exponentiere_rapida(mat, n);
int answer = (1LL * (1LL * x * mat[0][0] + 1LL * y * mat[1][0] + 1LL * z * mat[2][0])) % modulo;
fout << answer << '\n';
}
return 0;
}