Pagini recente » Cod sursa (job #92759) | Cod sursa (job #809016) | Cod sursa (job #710606) | Cod sursa (job #35473) | Cod sursa (job #3215673)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("iepuri.in");
ofstream g("iepuri.out");
typedef long long ll;
const int DIM = 3 + 1;
const ll MOD = 666013;
int t, n;
ll x, y, z, a, b, c, rez;
ll A[DIM][DIM], B[DIM][DIM], C[DIM][DIM];
void init(ll A[DIM][DIM]){
A[1][1] = A[1][3] = A[2][1] = A[2][2] = 0;
A[1][2] = A[2][3] = 1;
A[3][1] = c;
A[3][2] = b;
A[3][3] = a;
}
void unit(ll A[DIM][DIM]){
for(int i = 1; i <= DIM; ++i)
for(int j = 1; j <= DIM; ++j){
if(i == j)
A[i][j] = 1;
else
A[i][j] = 0;
}
}
void inmultire(ll A[DIM][DIM], ll B[DIM][DIM], ll C[DIM][DIM]){ /// A = B * C
for(int i = 1; i <= DIM; ++i)
for(int j = 1; j <= DIM; ++j){
A[i][j] = 0;
for(int k = 1; k <= DIM; ++k)
A[i][j] = (A[i][j] + (B[i][k] * C[k][j]) % MOD ) % MOD;
}
}
void atrib(ll A[DIM][DIM], ll B[DIM][DIM]){ /// A = B
for(int i = 1; i <= DIM; ++i)
for(int j = 1; j <= DIM; ++j)
A[i][j] = B[i][j];
}
void power(int n){ /// A ^ n
if(n == 0){
unit(A);
return;
}
init(A);
unit(B); /// B = I3
while(n){
if(n % 2 == 1){ /// B = B * A
inmultire(C, B, A);
atrib(B, C);
}
inmultire(C, A, A); /// A = A * A
atrib(A, C);
n >>= 1;
}
atrib(A, B);
}
int main()
{
f >> t;
while(t--){
f >> x >> y >> z >> a >> b >> c >> n;
power(n - 2);
rez = (A[3][1] * x) % MOD + (A[3][2] * y) % MOD + (A[3][3] * z) % MOD;
g << rez % MOD << '\n';
}
return 0;
}