Cod sursa(job #2698865)

Utilizator Gheorghita_VladGheorghita Vlad Gheorghita_Vlad Data 23 ianuarie 2021 10:51:25
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.35 kb
#include <bits/stdc++.h>
#define MOD 666013
#define ll long long
using namespace std;
ifstream f("iepuri.in");
ofstream g("iepuri.out");
ll a[3][3];
ll c[3][3];
ll sol[3][3];
int x,y,z;
int t,b,h;
int n,m;
void mult(ll a[3][3],ll b[3][3])
{
    ll c[3][3];
    int i,j,k;
    for(i=0; i<=2; i++)
    {
        for(j=0; j<=2; j++)
        {
            c[i][j]=0;
            for(k=0; k<=2; k++)
                c[i][j]+=a[i][k]*b[k][j];
            c[i][j]=c[i][j]%MOD;
        }
    }

    for(i=0; i<=2; i++)
        for(j=0; j<=2; j++)
            a[i][j]=c[i][j];
}
void put(ll sol[3][3],int k)
{
    while(k)
    {
        if(k%2==1)
        {
            mult(sol,c);
            k--;
        }
        else
        {
            mult(c,c);
            k/=2;
        }
    }
}
int main()
{
    f>>m;
    for (int i=1;i<=m;i++)
    {
        memset(sol,0,sizeof(sol));
        memset(a,0,sizeof(a));
        sol[0][0]=sol[1][1]=sol[2][2]=1;

        f>>x>>y>>z;
        a[0][0]=x;
        a[0][1]=y;
        a[0][2]=z;

        f>>t>>b>>h;
        c[0][0]=c[0][1]=0;
        c[0][2]=h;
        c[1][0]=1;
        c[1][1]=0;
        c[1][2]=b;
        c[2][0]=0;
        c[2][1]=1;
        c[2][2]=t;

        f>>n;
        put(sol,n);
        mult(a,sol);
        g<<a[0][0]<<'\n';
    }
    return 0;
}