Pagini recente » Borderou de evaluare (job #936698) | Cod sursa (job #557578) | Cod sursa (job #2291995) | Cod sursa (job #2341146) | Cod sursa (job #3238149)
#include<bits/stdc++.h>
std::ifstream fin("iepuri.in");
std::ofstream fout("iepuri.out");
const int64_t MOD = 666013;
int64_t T, X, Y, Z, A, B, C, N;
struct Matrix{
int n, m; //dimensiuni
std::vector<std::vector<int64_t> > mat; //folosim tipul int pe 64 de biti pentru a evita overflow-ul la inmultire
Matrix(int _n, int _m, bool id){
n = _n;
m = _m;
mat = std::vector<std::vector<int64_t> >(n, std::vector<int64_t>(m, 0));
if(id){
for(int i = 0; i < n; ++i)
mat[i][i] = 1;
}
}
Matrix operator*(const Matrix& other){
Matrix result(this-> n, other.m, false);
for(int k = 0; k < this->m; ++k)
for(int i = 0; i < this->n; ++i)
for(int j = 0; j < other.m; ++j)
result.mat[i][j] = (result.mat[i][j] + this->mat[i][k] * other.mat[k][j]) % MOD;
return result;
}
Matrix putere(int64_t exponent){
Matrix result(this->n, this->m, true);
for(int64_t i = 0; (1ll << i) <= exponent; ++i){
if((1ll << i) & exponent)
result = result * (*this);
(*this) = (*this) * (*this);
}
return result;
}
void print(){
for(int i = 0; i < this->n; ++i){
for(int j = 0; j < this->m; ++j)
fout << this->mat[i][j] << ' ';
fout << '\n';
}
}
};
int main(){
fin >> T;
for(;T--;){
fin >> X >> Y >> Z >> A >> B >> C >> N;
Matrix sol(3, 3, false);
sol.mat[0][0] = A;
sol.mat[0][1] = B;
sol.mat[0][2] = C;
sol.mat[1][0] = sol.mat[2][1] = 1;
sol = sol.putere(N - 2);
fout << (sol.mat[0][0] * Z + sol.mat[0][1] * Y + sol.mat[0][2] * X) % MOD << '\n';
}
}