Cod sursa(job #2188729)

Utilizator NeredesinI am not real Neredesin Data 27 martie 2018 13:37:03
Problema Iepuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <iostream>
#include <memory.h>
#include <fstream>

using namespace std;

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

typedef long long ll;

const int MOD = 666013;

int n, t;
ll a[6][6];
ll b[6][6];
ll x, y, z;

void prod(ll a[][6], ll b[][6]) {
  ll c[6][6];
  memset(c, 0, sizeof(c));

  for(int i = 1; i <= 3; i++)
    for(int j = 1; j <= 3; j++)
      for(int k = 1; k <= 3; k++)
        c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % MOD;
  memcpy(a, c, sizeof(c));
}

int main()
{
  in >> t;
  for(int test = 1; test <= t; test++) {
    memset(a, 0, sizeof(a));
    a[2][1] = 1;
    a[3][2] = 1;
    in >> x >> y >> z;
    in >> a[3][3] >> a[2][3] >> a[1][3] >> n;

    memcpy(b, a, sizeof(a));

    n--;
    while(n != 0) {
      if(n % 2 == 1) {
        prod(a, b);
        n--;
      } else {
        prod(b, b);
        n /= 2;
      }
    }

    out << (x * a[1][1] + y * a[2][1] + z * a[3][1]) % MOD << '\n';
  }

  in.close();
  out.close();
  return 0;
}