Pagini recente » Cod sursa (job #256427) | Cod sursa (job #1651246) | Monitorul de evaluare | Cod sursa (job #1206084) | Cod sursa (job #3288869)
/*
____ ___ _ ___ ____ _
/ ___| / _ \| | |_ _/ ___| / \
\___ \| | | | | | | | / _ \
___) | |_| | |___ | | |___ / ___ \
|____/ \___/|_____|___\____/_/ \_\
*/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long int
#define pii pair<int,int>
const int NMAX = 2e5+9;
const int MOD = 666013;
int binpow(int n, int k)
{
if (k==0)
{
return 1;
}
int x=binpow(n,k/2)%MOD;
if (k%2==0)
{
return x*x%MOD;
}
else
{
return x*x%MOD*n%MOD;
}
}
ifstream fin ("iepuri.in");
ofstream fout ("iepuri.out");
#define cin fin
#define cout fout
int x,y,z,a,b,c,n;
struct matrix
{
int mat[4][4];
int n,m;
};
matrix produs (matrix a, matrix b)
{
matrix c;
c.n=a.n,c.m=b.m;
for (int i=1; i<=c.n; i++)
{
for (int j=1; j<=c.m; j++)
{
c.mat[i][j]=0;
for (int k=1; k<=a.m; k++)
{
c.mat[i][j]+=a.mat[i][k]*b.mat[k][j];
c.mat[i][j]%=MOD;
}
}
}
return c;
}
matrix exp_rapida (matrix a, int n)
{
if (n==1)
{
return a;
}
matrix npe2=exp_rapida (a,n/2);
if (n%2==0)
{
return produs(npe2,npe2);
}
else
{
return produs(produs(npe2,npe2),a);
}
}
void run_case ()
{
cin>>x>>y>>z>>a>>b>>c>>n;
matrix init,expo;
init.n=3,init.m=1;
init.mat[1][1]=x,init.mat[2][1]=y,init.mat[3][1]=z;
expo.n=expo.m=3;
for (int i=1; i<=3; i++)
{
for (int j=1; j<=3; j++)
{
expo.mat[i][j]=0;
}
}
expo.mat[1][2]=expo.mat[2][3]=1;
expo.mat[3][1]=c,expo.mat[3][2]=b,expo.mat[3][3]=a;
matrix final=exp_rapida(expo,n-2);
matrix ans=produs (final,init);
cout<<ans.mat[3][1]<<'\n';
}
signed main ()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL),cout.tie ();
int teste;
cin>>teste;
while (teste--)
{
run_case();
}
}