Cod sursa(job #1199010)

Utilizator ArchazeyBaltatu Andrei-Mircea Archazey Data 17 iunie 2014 22:24:45
Problema Iepuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.36 kb
#include<fstream>
using namespace std;

struct mat
{
    long long tor[4][4];
};

ifstream fin("iepuri.in");
ofstream fout("iepuri.out");

const int modulo=666013;

int t;
int x,y,z,a,b,c,n;
mat cacat,w,aux;

inline mat Inmultire(mat cos,mat bos)
{
    int i,j,k;
    for (i=1;i<=3;i++)
        for (j=1;j<=3;j++) aux.tor[i][j]=0;
    for (i=1;i<=3;i++)
        {
            for (j=1;j<=3;j++)
                {
                    for (k=1;k<=3;k++)
                        aux.tor[i][j]+=(1LL*cos.tor[i][k]*bos.tor[k][j])%modulo;
                    aux.tor[i][j]%=modulo;
                }
        }
    return aux;
}

inline mat Log(int bes)
{
    if (bes==1) return w;
    else if (bes&1) return Inmultire(w,Log(bes-1));
    else
        {
            mat ca;
            ca=Log(bes>>1);
            return Inmultire(ca,ca);
        }
}

inline void Init()
{
    w.tor[1][1]=w.tor[3][1]=w.tor[1][2]=w.tor[2][2]=0;
    w.tor[2][1]=w.tor[3][2]=1;
    w.tor[1][3]=c;
    w.tor[2][3]=b;
    w.tor[3][3]=a;
}

int main()
{
    long long s;
    fin>>t;
    while (t--)
        {
            fin>>x>>y>>z>>a>>b>>c>>n;
            Init();
            cacat=Log(n-2);
            s=1LL*cacat.tor[1][3]*x+1LL*y*cacat.tor[2][3]+1LL*z*cacat.tor[3][3];
            s%=modulo;
            fout<<s<<"\n";
        }
    return 0;
}