Pagini recente » Cod sursa (job #1753771) | Cod sursa (job #1799895) | Cod sursa (job #2935721) | Cod sursa (job #3186465) | Cod sursa (job #3260116)
#include <fstream>
using namespace std;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
const int MOD = 666013;
void produs(int a[3][3], int b[3][3]){
int aux[3][3] = {0};
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
for(int k = 0; k < 3; k++)
aux[i][j] = ((long long)a[i][k] * b[k][j] + aux[i][j])% MOD;
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
a[i][j] = aux[i][j];
}
void putere(int p[3][3], int a[3][3], int n){
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
if(i == j)
p[i][j] = 1;
else
p[i][j] = 0;
}
}
while(n != 0){
int cifb = n % 2;
if(cifb != 0)
produs(p, a);
produs(a, a);
n /= 2;
}
}
int main(){
int t;
fin >> t;
for(int test = 0; test < t; test++){
int x, y, z, a, b, c, n;
fin >> x >> y >> z >> a >> b >> c >> n;
int mat[3][3] = {{a, b, c}, {1, 0, 0}, {0, 1, 0}}, p[3][3];
putere(p, mat, n - 2);
fout << ((long long)p[0][0] * z + (long long)p[0][1] * y + (long long)p[0][2] * x) % MOD << endl;
}
return 0;
}