Pagini recente » Cod sursa (job #2795671) | Cod sursa (job #1113143) | Cod sursa (job #968178) | Cod sursa (job #47779) | Cod sursa (job #2469310)
//wish me luck
#include <bits/stdc++.h>
using namespace std;
ifstream f("iepuri.in");
ofstream g("iepuri.out");
const int mod = 666013;
int T,x,y,z,a,b,c,n,dp[4][4], dp2[4][4];
void multiplication(int a[4][4], int b[4][4]){
int c[4][4],i,j,k;
//memset(c,0,sizeof(c));
for(i = 1 ; i <= 3 ; i++)
for(j = 1 ; j <= 3 ; j++)
c[i][j] = 0;
for(i = 1 ; i <= 3 ; i++)
for(j = 1 ; j <= 3 ; j++)
for(k = 1 ; k <= 3 ; k++)
c[i][j] = (c[i][j] + (1LL * a[i][k] * b[k][j]) % mod) % mod;
for(i = 1 ; i <= 3 ; i++)
for(j = 1 ; j <= 3 ; j++)
a[i][j] = c[i][j];
}
void pow(int x){
int mat[4][4],i,j;
mat[1][1] = mat[1][3] = mat[2][1] = mat[2][2] = 0;
mat[1][2] = mat[2][3] = 1;
mat[3][1] = c;
mat[3][2] = b;
mat[3][3] = a;
while(x > 0){
if(x % 2 == 1){
multiplication(mat,dp);
x--;
}else{
multiplication(dp, dp);
x /= 2;
}
}
for(i = 1 ; i <= 3 ; i++)
for(j = 1 ; j <= 3 ; j++)
dp[i][j] = mat[i][j];
}
int main(){
int i,j;
f >> T;
while(T--){
f >> x >> y >> z >> a >> b >> c >> n;
dp[1][1] = dp[1][3] = dp[2][1] = dp[2][2] = 0;
dp[1][2] = dp[2][3] = 1;
dp[3][1] = c;
dp[3][2] = b;
dp[3][3] = a;
pow(n - 3);
dp2[1][1] = x;
dp2[2][1] = y;
dp2[3][1] = z;
dp2[1][2] = dp2[1][3] = dp2[2][2] = dp2[2][3] = dp2[3][2] = dp2[3][3] = 0;
multiplication(dp, dp2);
g << dp[3][1] << "\n";
}
return 0;
}