Cod sursa(job #2629170)

Utilizator drknss_Hehe hehe drknss_ Data 19 iunie 2020 12:55:06
Problema Iepuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.16 kb
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#define int long long

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

const ll inf = 2e9;
const ll mod = 666013;
const int N = 1 + 11;
const int NMAX = 1e4 + 11;
const ll INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);

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

int n, a[N][N], ans[N][N], b[N][N];



void mult1(){

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                b[i][j] += ans[i][k]*a[k][j];
                b[i][j] %= mod;
            }
        }
    }

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            ans[i][j] = b[i][j];
            b[i][j] = 0;
        }
    }

}

void mult2(){

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                b[i][j] += a[i][k]*a[k][j];
                b[i][j] %= mod;
            }
        }
    }

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            a[i][j] = b[i][j];
            b[i][j] = 0;
        }
    }

}
void poww(int p){

    while(p){

        if(p % 2)mult1();
        mult2();
        p /= 2;

    }
}

void solve(){

    int X,Y,Z,A,B,C;

    in >> X >> Y >> Z >> A >> B >> C >> n;

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            ans[i][j] = (i == j ? 1 : 0);
        }
    }

    a[0][0] = 0; a[0][1] = 1; a[0][2] = 0;
    a[1][0] = 0; a[1][1] = 0; a[1][2] = 1;
    a[2][0] = C; a[2][1] = B; a[2][2] = A;


    poww(n - 2);

    out << (ans[2][0]*X + ans[2][1]*Y + ans[2][2]*Z + mod)%mod << '\n';

}

int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();

    //cout << setprecision(20) << fixed;

    int t = 1;
    in >> t;
    while(t--){
        solve();
    }
}