Cod sursa(job #708546)

Utilizator vendettaSalajan Razvan vendetta Data 6 martie 2012 21:58:30
Problema Iepuri Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.47 kb
#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, n;
//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 mm[4][4], int p){

    for(int i=0; (1<<i) <=p; i++){
        if (((1<<i) & p) > 0)
            inmul(rez, mm);
        inmul(mm,mm);
    }

}

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;

}