Cod sursa(job #3276428)

Utilizator tudor_costinCostin Tudor tudor_costin Data 13 februarie 2025 17:17:17
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.61 kb
#include <bits/stdc++.h>

using namespace std;
#define int long long
const int mod=666013;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
struct mat
{
    int m[3][3];
    mat operator*(const mat b)
    {
        mat c;
        for(int i=0;i<3;i++)
        {
            for(int j=0;j<3;j++)
            {
                c.m[i][j]=0;
                for(int k=0;k<3;k++)
                {
                    c.m[i][j]+=m[i][k]*b.m[k][j]%mod;
                    c.m[i][j]%=mod;
                }
            }
        }
        return c;
    }
};
void init(mat& a)
{
    a.m[0][0]=1;
    a.m[0][1]=0;
    a.m[0][2]=0;
    a.m[1][0]=0;
    a.m[1][1]=1;
    a.m[1][2]=0;
    a.m[2][0]=0;
    a.m[2][1]=0;
    a.m[2][2]=1;
}
mat power(mat& a, int b)
{
    mat sol;
    init(sol);
    while(b)
    {
        if(b&1) sol=sol*a;
        a=a*a;
        b=b/2;
    }
    return sol;
}
void solve()
{
    int x,y,z,a,b,c,n;
    fin>>x>>y>>z>>a>>b>>c>>n;
    mat mult;
    mat fini;
    fini.m[0][0]=z;
    fini.m[0][1]=0;
    fini.m[0][2]=0;
    fini.m[1][0]=y;
    fini.m[1][1]=0;
    fini.m[1][2]=0;
    fini.m[2][0]=x;
    fini.m[2][1]=0;
    fini.m[2][2]=0;
    ///mult.m =[[a,b,c],[1,0,0],[0,1,0]];
    mult.m[0][0]=a;
    mult.m[0][1]=b;
    mult.m[0][2]=c;
    mult.m[1][0]=1;
    mult.m[1][1]=0;
    mult.m[1][2]=0;
    mult.m[2][0]=0;
    mult.m[2][1]=1;
    mult.m[2][2]=0;
    mat ans=power(mult,n);
    ans=ans*fini;
    fout<<ans.m[2][0]<<'\n';
}
signed main()
{
    int t;
    fin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}