Cod sursa(job #708948)

Utilizator vendettaSalajan Razvan vendetta Data 7 martie 2012 16:12:44
Problema Iepuri Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.35 kb
#include <cstdio>
#define ll long long
#define MOD 666013

using namespace std;

ll rez[4][4], M[4][4];
ll n;
int a, b, c, x, y, z;
int T;

void citeste(){

    scanf("%d\n", &T);

}

void inmul(ll y[4][4], ll o[4][4]){

    ll aux[4][4] = {0LL};

    for(int l=0; l<3; l++){
        for(int c=0; c<3; c++){
            for(int i=0; i<3; i++){
                aux[l][c] += y[l][i] * o[i][c];
                //if (aux[l][c] > MOD)
                aux[l][c] = aux[l][c] % MOD;
            }
        }
    }

    for(int i=0; i<3; i++) for(int j=0; j<3; j++) y[i][j] = aux[i][j];

}

void put(ll 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){
        scanf("%d %d %d %d %d %d %d\n", &x, &y, &z, &a, &b, &c, &n);
        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] = 1; rez[1][1] = 1; rez[2][2] = 1;
        put(n-2);
        printf("%d\n", (((((x * rez[2][0]) % MOD) + y * rez[2][1]) % MOD) + z * rez[2][2]) % MOD );
    }

}

int main(){

    freopen("iepuri.in", "r", stdin);
    freopen("iepuri.out", "w", stdout);

    citeste();
    rezolva();

    fclose(stdin);
    fclose(stdout);

    return 0;

}