Pagini recente » Cod sursa (job #400493) | Cod sursa (job #2221420) | Cod sursa (job #3125432) | Cod sursa (job #1668741) | Cod sursa (job #3314753)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
struct Matrice {
int n, m;
long long v[3][3];
};
const long long MOD = 666013;
long long x, y, z, a, b, c, n;
Matrice mat, rasp;
static inline void Prod(Matrice& a, Matrice b) {
Matrice c;
c.n = a.n;
c.m = b.m;
memset(c.v, 0, sizeof(c.v));
for(int i = 0; i < a.n; i++) {
for(int j = 0; j < b.m; j++) {
for(int k = 0; k < a.m; k++) {
c.v[i][j] = (c.v[i][j] + (a.v[i][k] * b.v[k][j]) % MOD) % MOD;
}
}
}
a.n = c.n;
a.m = c.m;
for(int i = 0; i < c.n; i++) {
for(int j = 0; j < c.m; j++) {
a.v[i][j] = c.v[i][j];
}
}
}
static inline void Put(Matrice& a, int n) {
Matrice p;
p.n = a.n;
p.m = a.m;
memset(p.v, 0, sizeof(p.v));
p.v[0][0] = 1;
p.v[1][1] = 1;
p.v[2][2] = 1;
while(n) {
if(n & 1) Prod(p, a);
Prod(a, a);
n >>= 1;
}
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) a.v[i][j] = p.v[i][j];
}
}
static inline void Test() {
fin >> x >> y >> z >> a >> b >> c >> n;
mat.n = mat.m = 3;
memset(mat.v, 0, sizeof(mat.v));
mat.v[1][0] = 1;
mat.v[2][1] = 1;
mat.v[0][2] = c;
mat.v[1][2] = b;
mat.v[2][2] = a;
Put(mat, n);
rasp.n = 1;
rasp.m = 3;
rasp.v[0][0] = x;
rasp.v[0][1] = y;
rasp.v[0][2] = z;
Prod(rasp, mat);
fout << rasp.v[0][0] << "\n";
}
int main() {
fin.tie(NULL);
fout.tie(NULL);
int t;
fin >> t;
while(t--) Test();
return 0;
}