Pagini recente » Cod sursa (job #865060) | Cod sursa (job #255164) | Cod sursa (job #3346428) | Cod sursa (job #229757) | Cod sursa (job #3344093)
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define ll long long
int x,y,z,a,b,c,n,t;
const int MOD = 666013;
struct matrix{
long long mat[3][3];
void init(){
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
this->mat[i][j] = 0;
}
};
matrix multiply(matrix a, matrix b){
matrix rasp;
rasp.init();
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
for(int k = 0; k < 3; k++){
rasp.mat[i][j] = (rasp.mat[i][j] + a.mat[i][k] * b.mat[k][j]) % MOD;
}
}
}
return rasp;
}
matrix log_pow(matrix a, long long put){
matrix rasp;
rasp.init();
for(int i =0; i < 3; i++)
rasp.mat[i][i] = 1;
while(put){
if(put & 1)
rasp = multiply(rasp,a);
put >>= 1;
a = multiply(a,a);
}
return rasp;
}
void read(){
cin >> x >> y >> z >> a >> b >> c >> n;
}
void solve(){
matrix t;
t.init();
t.mat[0][0] = a;
t.mat[0][1] = b;
t.mat[0][2] = c;
t.mat[1][0] = 1;
t.mat[2][1] = 1;
matrix rasp = log_pow(t,n-2);
long long ans = (1LL * rasp.mat[0][0] * z) % MOD;
ans = (ans + 1LL * rasp.mat[0][1] * y) % MOD;
ans = (ans + 1LL * rasp.mat[0][2] * x) % MOD;
cout << ans << '\n';
}
int main() {
freopen("iepuri.in","r",stdin);
freopen("iepuri.out","w",stdout);
cin >> t;
while(t--){
read();
solve();
}
return 0;
}