Pagini recente » Cod sursa (job #1434791) | Cod sursa (job #448998) | Cod sursa (job #2647865) | Cod sursa (job #2936924) | Cod sursa (job #577351)
Cod sursa(job #577351)
#include<stdio.h>
#define mod 666013
FILE *F=fopen("iepuri.in","r");
FILE *G=fopen("iepuri.out","w");
long long a,b,c,x0,x1,x2;
long long n;
long long M[5][5],A[5][5];
void mat()
{
int i,j;
for(i=1;i<=3;++i)
for(j=1;j<=3;++j)
A[i][j]=M[i][j]=0;
A[1][2]=A[2][3]=M[1][2]=M[2][3]=1;
A[3][1]=M[3][1]=c;
A[3][2]=M[3][2]=b;
A[3][3]=M[3][3]=a;
}
void matrice(long long Q[5][5],long long R[5][5])
{
int i,j,k;
long long P[5][5],s=0;
for(i=1;i<=3;++i)
for(j=1;j<=3;++j)
{
s=0;
for(k=1;k<=3;++k)
s=(s+(Q[i][k]*R[k][j])%mod)%mod;
P[i][j]=s;
}
for(i=1;i<=3;++i)
for(j=1;j<=3;++j)
Q[i][j]=P[i][j];
}
void calcul(long long n)
{
if(n<=1) return;
calcul(n/2);
matrice(M,M);
if(n%2==1) matrice(M,A);
}
void afis()
{
long long s=0;
s=(M[3][1]*x0)%mod;
s=(s+ (M[3][2]*x1)%mod) %mod;
s=(s+ (M[3][3]*x2)%mod) %mod;
fprintf(G,"%lld\n",s);
}
int main()
{
long i,t;
fscanf(F,"%ld",&t);
for(i=1;i<=t;++i)
{
fscanf(F,"%lld%lld%lld%lld%lld%lld%lld",&x0,&x1,&x2,&a,&b,&c,&n);
mat();
calcul(n-2);
afis();
}
fclose(F);
fclose(G);
return 0;
}