Cod sursa(job #1584978)

Utilizator claudiuarseneClaudiu Arsene claudiuarsene Data 30 ianuarie 2016 17:26:55
Problema Iepuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <fstream>
using namespace std;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
const int MOD = 666013;
int x, y, z, a, b, c, n;
int mulmat(int a[][3], int b[][3]){
    int c[3][3];
    for(int i=0; i<3; i++)
    for(int j=0; j<3; j++){
        c[i][j] = 0;
        for(int k=0; k<3; k++)
            c[i][j] =(c[i][j] + (long long) a[i][k]*b[k][j])%MOD;
    }
    for(int i=0; i<3; i++)
    for(int j=0; j<3; j++)
        a[i][j] = c[i][j];
}
int solve(){
    int mat[3][3]={{0, 1, 0}, {0, 0, 1}, {c, b, a}};
    int ans[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
    for(; n; n>>=1){
        if(n&1)
            mulmat(ans, mat);
        mulmat(mat, mat);
    }
    return ((long long)ans[0][0]*x + (long long)ans[0][1]*y + (long long)ans[0][2]*z)%MOD;
}
int main()
{
    int t;
    fin>>t;
    while(t--){
        fin>>x>>y>>z>>a>>b>>c>>n;
        fout<<solve()<<'\n';
    }
    return 0;
}