Pagini recente » Cod sursa (job #1018894) | Diferente pentru problema/arb4 intre reviziile 7 si 6 | Cod sursa (job #2614339) | Cod sursa (job #1052123) | Cod sursa (job #1557203)
#include <fstream>
#define mod 666013
using namespace std;
ifstream f("iepuri.in");
ofstream g("iepuri.out");
long long n;
int t,x,y,Z,a,b,c;
struct matrice{long long poz11,poz12,poz13,poz21,poz22,poz23,poz31,poz32,poz33;}mat1,mat2,identitate,z,v,w;
matrice inmultire(matrice x,matrice y)
{
z.poz11=((1LL*x.poz11*y.poz11)%mod+(1LL*x.poz12*y.poz21)%mod+(1LL*x.poz13*y.poz31)%mod)%mod;
z.poz12=((1LL*x.poz11*y.poz12)%mod+(1LL*x.poz12*y.poz22)%mod+(1LL*x.poz13*y.poz32)%mod)%mod;
z.poz13=((1LL*x.poz11*y.poz13)%mod+(1LL*x.poz12*y.poz23)%mod+(1LL*x.poz13*y.poz33)%mod)%mod;
z.poz21=((1LL*x.poz21*y.poz11)%mod+(1LL*x.poz22*y.poz21)%mod+(1LL*x.poz23*y.poz31)%mod)%mod;
z.poz22=((1LL*x.poz21*y.poz12)%mod+(1LL*x.poz22*y.poz22)%mod+(1LL*x.poz23*y.poz32)%mod)%mod;
z.poz23=((1LL*x.poz21*y.poz13)%mod+(1LL*x.poz22*y.poz23)%mod+(1LL*x.poz23*y.poz33)%mod)%mod;
z.poz31=((1LL*x.poz31*y.poz11)%mod+(1LL*x.poz32*y.poz21)%mod+(1LL*x.poz33*y.poz31)%mod)%mod;
z.poz32=((1LL*x.poz31*y.poz12)%mod+(1LL*x.poz32*y.poz22)%mod+(1LL*x.poz33*y.poz32)%mod)%mod;
z.poz33=((1LL*x.poz31*y.poz13)%mod+(1LL*x.poz32*y.poz23)%mod+(1LL*x.poz33*y.poz33)%mod)%mod;
return z;
}
matrice putere(long long p)
{if(!p)
return identitate;
else
{matrice aux=putere(p/2);
aux=inmultire(aux,aux);
if(p&1)
aux=inmultire(mat1,aux);
return aux;
}
}
int main()
{
f>>t;
int i;
identitate.poz11=1;
identitate.poz22=1;
identitate.poz33=1;
for(i=1; i<=t; i++)
{
f>>x>>y>>Z>>a>>b>>c>>n;
mat2.poz11=x;
mat2.poz21=y;
mat2.poz31=Z;
mat1.poz12=1;
mat1.poz23=1;
mat1.poz31=c;
mat1.poz32=b;
mat1.poz33=a;
v=putere(n-2);
w=inmultire(v,mat2);
g<<w.poz31<<'\n';
}
return 0;
}