Cod sursa(job #406261)

Utilizator jupanubv92Popescu Marius jupanubv92 Data 1 martie 2010 13:04:36
Problema Iepuri Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.03 kb
#include<stdio.h>
#include<string.h>
#define Nmx 4
#define MOD 666013

int a[Nmx][Nmx],sol[Nmx][Nmx];
int X,Y,Z,A,B,C,n;

void mult(int x[Nmx][Nmx],int y[Nmx][Nmx])
{
    int s[Nmx][Nmx];
    memset(s,0,sizeof(s));
    for(int i=1;i<=3;++i)
        for(int j=1;j<=3;++j)
            for(int k=1;k<=3;++k)
                s[i][j]=(s[i][j]+x[i][k]*y[k][j])%MOD;
    memcpy(x,s,sizeof(s));
}

int main()
{
    freopen("iepuri.in","r",stdin);
    freopen("iepuri.out","w",stdout);
    int T;
    scanf("%d",&T);
    for(;T;--T)
    {
        scanf("%d%d%d%d%d%d%d",&X,&Y,&Z,&A,&B,&C,&n);
        memset (a,0,sizeof (a));
        a[1][2]=a[2][3]=1;
        a[3][1]=C;
        a[3][2]=B;
        a[3][3]=A;
        memset (sol,0,sizeof (sol));
        sol[1][1]=sol[2][2]=sol[3][3]=1;
        while(n)
        {
            if(n%2)
                mult(sol,a);
            mult(a,a);
            n/=2;
        }
        printf("%d\n",((sol[1][1]*X)%MOD+(sol[1][2]*Y)%MOD+(sol[1][3]*Z)%MOD)%MOD);
    }
    return 0;
}