Pagini recente » Cod sursa (job #1888107) | Cod sursa (job #2520056) | Cod sursa (job #2213429) | Cod sursa (job #2173370) | Cod sursa (job #1233784)
#include <iostream>
#include <fstream>
#define MOD 666013
using namespace std;
int easy_find[5][5], aux[5][5], unit[5][5], my[5][5];
void assign_mat(int a[5][5], int b[5][5], int n){
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
a[i][j] = b[i][j];
}
void write(int a[5][5], int n){
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++)
cout << a[i][j] << " ";
cout << '\n';
}
cout << '\n';
}
void wipe(int a[5][5], int n){
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
a[i][j] = 0;
}
void multiply_mat(int a[5][5], int b[5][5], int n){
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++){
aux[i][j] = 0;
for(int k = 0; k < n; k++){
aux[i][j] += (a[i][k] * b[k][j]) % MOD;
if(aux[i][j] >= MOD)
aux[i][j] %= MOD;
if(aux[i][j] < 0)
aux[i][j] = MOD - aux[i][j];
}
}
assign_mat(a, aux, n);
}
void power(int a[5][5], int res[5][5], int n, long long exp){
if(exp == 0)
assign_mat(res, unit, n);
else{
if(exp == 1){
multiply_mat(res, a, n);
return;
}
else{
if(exp % 2)
multiply_mat(res, a, n);
multiply_mat(a, a, n);
power(a, res, n, exp / 2);
}
}
}
int main()
{
int x, y, z, a, b, c, tests;
long long n;
fstream f("iepuri.in", ios::in);
fstream g("iepuri.out", ios::out);
unit[0][0] = unit[1][1] = unit[2][2] = 1;
f >> tests;
for(int i = 0; i < tests; i++){
f >> x >> y >> z >> a >> b >> c >> n;
wipe(easy_find, 3);
easy_find[1][0] = easy_find[2][1] = 1;
easy_find[0][2] = c;
easy_find[1][2] = b;
easy_find[2][2] = a;
assign_mat(my, unit, 3);
power(easy_find, my, 3, n-2);
assign_mat(easy_find, my, 3);
int sum = x * easy_find[0][2] % MOD + y * easy_find[1][2] % MOD + z * easy_find[2][2] % MOD;
g << sum % MOD << '\n';
}
return 0;
}