Pagini recente » Cod sursa (job #443727) | Cod sursa (job #350242) | Cod sursa (job #1688160) | Cod sursa (job #2629391) | Cod sursa (job #2266014)
#include<fstream>
using namespace std;
ifstream f("iepuri.in");
ofstream g("iepuri.out");
int v[9];
void prodmatrice(int o[9],int u[9],int s[9])
{
s[0]=(1LL*o[0]*u[0]+1LL*o[1]*u[3]+1LL*o[2]*u[6])%666013;
s[1]=(1LL*o[0]*u[1]+1LL*o[1]*u[4]+1LL*o[2]*u[7])%666013;
s[2]=(1LL*o[0]*u[2]+1LL*o[1]*u[5]+1LL*o[2]*u[8])%666013;
s[3]=(1LL*o[3]*u[0]+1LL*o[4]*u[3]+1LL*o[5]*u[6])%666013;
s[4]=(1LL*o[3]*u[1]+1LL*o[4]*u[4]+1LL*o[5]*u[7])%666013;
s[5]=(1LL*o[3]*u[2]+1LL*o[4]*u[5]+1LL*o[5]*u[8])%666013;
s[6]=(1LL*o[6]*u[0]+1LL*o[7]*u[3]+1LL*o[8]*u[6])%666013;
s[7]=(1LL*o[6]*u[1]+1LL*o[7]*u[4]+1LL*o[8]*u[7])%666013;
s[8]=(1LL*o[6]*u[2]+1LL*o[7]*u[5]+1LL*o[8]*u[8])%666013;
}
void putere(int x, int s[9])
{
int c[9],i,aux[9],j;
for(i=0;i<=8;i++)
c[i]=v[i];
for(i=0;i<=8;i++)
s[i]=0;
s[0]=1;
s[4]=1;
s[8]=1;
for(j=0;(1LL<<j)<=x;j++)
{
if((1LL<<j)&x)
{
prodmatrice(s,c,aux);
for(i=0;i<=8;i++)
s[i]=aux[i];
}
prodmatrice(c,c,aux);
for(i=0;i<=8;i++)
c[i]=aux[i];
}
}
int main()
{
int n,s[9],m,x,y,z,a,b,c,i;
f>>m;
for(i=1;i<=m;i++)
{
f>>x>>y>>z>>a>>b>>c>>n;
v[0]=0;v[1]=1;v[2]=0;
v[3]=0;v[4]=0;v[5]=1;
v[6]=c;v[7]=b;v[8]=a;
putere(n-2,s);
g<<(1LL*s[6]*x+1LL*s[7]*y+1LL*s[8]*z)%666013<<"\n";
}
}