Pagini recente » Cod sursa (job #1775324) | Cod sursa (job #2474563) | Cod sursa (job #1557206) | Cod sursa (job #3245591) | Cod sursa (job #1611872)
#include <fstream>
#define p 666013
using namespace std;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
void produs(int a[4][4],int n)
{ int b[4][4],c[4][4],i,j,k;
for(i=1;i<=3;i++)
for(j=1;j<=3;j++) b[i][j]=a[i][j];
if(n>1)
{ //calculez b*b si rezultatul in pun in a
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
{ a[i][j]=0;
for(k=1;k<=3;k++) a[i][j]=(a[i][j]+(1LL*b[i][k]*b[k][j])%p)%p;
}
if(n%2==0) produs(a,n/2);
else {produs(a,(n-1)/2);
for(i=1;i<=3;i++)
for(j=1;j<=3;j++) c[i][j]=a[i][j];
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
{ a[i][j]=0;
for(k=1;k<=3;k++) a[i][j]=(a[i][j]+(1LL*b[i][k]*c[k][j])%p)%p;
}
}
}
}
int main()
{ int t,x,y,z,a,b,c,n,m[4][4],i,term;
fin>>t;
for(i=1;i<=t;++i)
{ fin>>x>>y>>z>>a>>b>>c>>n;
m[1][1]=m[1][2]=m[2][2]=m[3][1]=0;
m[2][1]=m[3][2]=1;
m[1][3]=c; m[2][3]=b; m[3][3]=a;
produs(m,n-2);
term=(1LL*x*m[1][3]%p+1LL*y*m[2][3]%p+1LL*z*m[3][3]%p)%p;
fout<<term<<"\n";
}
return 0;
}