Cod sursa(job #3321651)

Utilizator FRD233Fodor Rares-Costin FRD233 Data 10 noiembrie 2025 18:53:49
Problema Iepuri Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.02 kb
/*#include <bits/stdc++.h>
using namespace std;
ifstream f("iepuri.in");
ofstream g("iepuri.out");
#define MOD 666013
int T,x,y,z,A,B,c,n;
int C[4][4],R[4][4];
int sol;
void prodM(int A[4][4],int B[4][4], int C[4][4])
{   int X[4][4];
    for(int i=1;i<=3;i++)
        for(int j=1;j<=3;j++)
        {   unsigned long long sum=0;
            for(int k=1;k<=3;k++)
                sum+=((1LL*A[i][k]*B[k][j])%MOD);
            X[i][j]=sum%MOD;
        }
    for(int i=1;i<=3;i++)
        for(int j=1;j<=3;j++) C[i][j]=X[i][j];
}
void powerM(int C[4][4], int n, int R[4][4])
{   int X[4][4];
    for(int i=1;i<=3;i++)
        for(int j=1;j<=3;j++) X[i][j]=1*(i==j);
    //for(int i=1;i<=3;i++,cout<<'\n')
        //for(int j=1;j<=3;j++) cout<<X[i][j]<<" ";
    while(n>1)
    {   if(n%2==0)
        {   prodM(C,C,C);
            n/=2;
        }
        else
        {   prodM(X,C,X);
            n--;
        }
        prodM(C,X,R);
    }
}
int main()
{   f>>T;
    while(T--)
    {   f>>x>>y>>z>>A>>B>>c>>n;
        for(int i=1;i<=3;i++)
            for(int j=1;j<=3;j++) C[i][j]=0;
        C[2][1]=C[3][2]=1;
        C[1][3]=c,C[2][3]=B,C[3][3]=A;
        if(n==0) g<<x<<'\n';
        else if(n==1) g<<y<<'\n';
        else if(n==2) g<<z<<'\n';
        else
        {    powerM(C,n-2,R);
             sol=((1LL*x*R[1][3])%MOD+(1LL*y*R[2][3])%MOD+(1LL*z*R[3][3])%MOD)%MOD;
             g<<sol<<'\n';
        }
    }

    return 0;
}*/
#include <bits/stdc++.h>
using namespace std;
ifstream f("iepuri.in");
ofstream g("iepuri.out");
#define MOD 666013
int T,x,y,z,A,B,C,n,w;
int main()
{   f>>T;
    while(T--)
    {   f>>x>>y>>z>>A>>B>>C>>n;
        if(n==0) g<<x<<'\n';
        else if(n==1) g<<y<<'\n';
        else if(n==2) g<<z<<'\n';
        else
        {   for(int i=3;i<=n;i++)
            {   w=((1LL*A*z)%MOD+(1LL*B*y)%MOD+(1LL*C*x)%MOD)%MOD;
                x=y;
                y=z;
                z=w;
            }
            g<<z<<'\n';
        }
    }

    return 0;
}