Pagini recente » Cod sursa (job #449469) | Monitorul de evaluare | Istoria paginii utilizator/aaaa1111aaaa | Cod sursa (job #2073288) | Cod sursa (job #708540)
Cod sursa(job #708540)
#include <fstream>
#define ll long long
#define MOD 666013
using namespace std;
ll m[4][4], rez[4][4];
int T;
ll a, b, c, x, y, z;
int n;
ifstream f("iepuri.in");
ofstream g("iepuri.out");
void citeste(){
f >> T;
}
void inmul(ll y[4][4], ll o[4][4]){
ll aux[4][4]={0LL};
for(int i=0; i<3; i++){
for(int j=0; j<3; j++){
//aux[i][j] = 0;
for(int w=0; w<3; w++){
aux[i][j] += y[i][w] * o[w][j];
if (aux[i][j] > MOD) aux[i][j] = aux[i][j] % MOD;
}
}
}
for(int i=0; i<3; i++)
for(int j=0; j<3; j++) y[i][j] = aux[i][j];
}
void put(ll m[4][4], int p){
for(int i=0; (1<<i) <=p; i++){
if (((1<<i) & p) > 0)
inmul(rez, m);
inmul(m,m);
}
}
void rezolva(){
for(; T; --T){
f >> x >> y >> z >> a >> b >> c >> n;
//m[3][3] = { {0, 1, 0}, {0, 0, 1}, {c, b, a} };
m[0][0] = m[0][2] = m[1][0] = m[1][1] = 0;
m[0][1] = m[1][2] = 1;
m[2][0] = c; m[2][1] = b; m[2][2] = a;
for(int i=0; i<3; i++) for(int j=0; j<3; j++) rez[i][j] = 0;
rez[0][0] = rez[1][1] = rez[2][2] = 1;
put(m, n);
/*
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) g << rez[i][j] << " ";
g << "\n";
}
*/
g << rez[0][0] * x + rez[0][1] * y + rez[0][2] * z << "\n";
}
}
int main(){
citeste();
rezolva();
f.close();
g.close();
return 0;
}