Pagini recente » Cod sursa (job #2528062) | Cod sursa (job #2623341) | Cod sursa (job #1646578) | Cod sursa (job #580557) | Cod sursa (job #3227299)
#include <fstream>
using namespace std;
ifstream f("iepuri.in");
ofstream g("iepuri.out");
const int mod = 666013;
int t, x, y, z, a, b, c, n;
struct mat{
int m[3][3];
};
mat nullmatrice = {
{{1, 0, 0},
{0, 1, 0},
{0, 0, 1}}
};
mat produs(mat a, mat b){
mat c;
c.m[0][0] = (1LL * a.m[0][0] * b.m[0][0] + 1LL * a.m[0][1] * b.m[1][0] + 1LL * a.m[0][2] * b.m[2][0]) % mod;
c.m[0][1] = (1LL * a.m[0][0] * b.m[0][1] + 1LL * a.m[0][1] * b.m[1][1] + 1LL * a.m[0][2] * b.m[2][1]) % mod;
c.m[0][2] = (1LL * a.m[0][0] * b.m[0][2] + 1LL * a.m[0][1] * b.m[1][2] + 1LL * a.m[0][2] * b.m[2][2]) % mod;
c.m[1][0] = (1LL * a.m[1][0] * b.m[0][0] + 1LL * a.m[1][1] * b.m[1][0] + 1LL * a.m[1][2] * b.m[2][0]) % mod;
c.m[1][1] = (1LL * a.m[1][0] * b.m[0][1] + 1LL * a.m[1][1] * b.m[1][1] + 1LL * a.m[1][2] * b.m[2][1]) % mod;
c.m[1][2] = (1LL * a.m[1][0] * b.m[0][2] + 1LL * a.m[1][1] * b.m[1][2] + 1LL * a.m[1][2] * b.m[2][2]) % mod;
c.m[2][0] = (1LL * a.m[2][0] * b.m[0][0] + 1LL * a.m[2][1] * b.m[1][0] + 1LL * a.m[2][2] * b.m[2][0]) % mod;
c.m[2][1] = (1LL * a.m[2][0] * b.m[0][1] + 1LL * a.m[2][1] * b.m[1][1] + 1LL * a.m[2][2] * b.m[2][1]) % mod;
c.m[2][2] = (1LL * a.m[2][0] * b.m[0][2] + 1LL * a.m[2][1] * b.m[1][2] + 1LL * a.m[2][2] * b.m[2][2]) % mod;
return c;
}
mat exponentiere(mat a, int n){
if(n == 0) return nullmatrice;
else{
mat nr = exponentiere(a, n / 2);
if(n % 2 == 1){
return produs(a, produs(nr, nr));
}
else return produs(nr, nr);
}
}
int main(){
f >> t;
while(t--){
f >> x >> y >> z >> a >> b >> c >> n;
mat matrice = {
{{0, 1, 0},
{0, 0, 1},
{c, b, a}}
};
int sol = 0;
mat rez = exponentiere(matrice, n);
sol = rez.m[0][0] * x + rez.m[0][1] * y + rez.m[0][2] * z;
g << sol << '\n';
}
}