Pagini recente » Cod sursa (job #2565698) | Cod sursa (job #1445619) | Cod sursa (job #1763967) | Cod sursa (job #2265836) | Cod sursa (job #2150529)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("iepuri.in");
ofstream fout("iepuri.out");
typedef long long matrix[4][4];
const int mod = 666013;
int t, x, y, z, a, b, c, nn;
matrix REZ, A;
void empty(matrix a){
for(int i = 1; i<=3; ++i)
for(int j = 1; j<=3; ++j)
a[i][j] = 0;
}
void print(matrix a){
for(int i = 1; i<=3; ++i, cout << "\n")
for(int j = 1; j<=3; ++j, cout << " ")
cout << a[i][j];
cout << endl;
}
void copy(matrix from, matrix to){
for(int i = 1; i<=3; ++i)
for(int j = 1; j<=3; ++j)
to[i][j] = from[i][j];
}
void multiply(matrix a, matrix b, matrix c){
for(int i = 1; i<=3; ++i)
for(int j = 1; j<=3; ++j){
c[i][j] = 0;
for(int k = 1; k<=3; ++k)
c[i][j] += ((a[i][k]%mod)*(b[k][j]%mod))%mod;
c[i][j] %= mod;
}
}
void inmlog(int n){
matrix temp;
while(n){
if(n & 1){
multiply(REZ, A, temp);
copy(temp, REZ);
n--;
}
multiply(A, A, temp);
copy(temp, A);
n >>= 1;
}
}
int main()
{
fin >> t;
while(t--){
fin >> x >> y >> z >> a >> b >> c >> nn;
empty(A); empty(REZ);
for(int i = 1; i<=3; ++i)
REZ[i][i] = 1;
A[1][3] = c;
A[2][3] = b;
A[3][3] = a;
A[2][1] = 1;
A[3][2] = 1;
inmlog(nn-2);
//print(REZ);
fout << ((x * REZ[1][3]) % mod + (y * REZ[2][3]) % mod + (z * REZ[3][3]) % mod) % mod<< "\n";
}
return 0;
}