Cod sursa(job #844155)

Utilizator hiticas_abelhiticasabel hiticas_abel Data 28 decembrie 2012 21:05:11
Problema Iepuri Scor 100
Compilator cpp Status done
Runda 23dezile_2 Marime 1.9 kb
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
#define MOD 666013 
#define input  "iepuri.in"
#define output "iepuri.out"
 
ifstream fin (input);
ofstream fout(output);
 
int iep(long n);
int t,x,y,z,a,b,c,n,i; 
 
long long M[4][4], I3[4][4];
 
void mult();
void mult1();
 
int main()
{
     fin >> t;
      
     for (i = 1; i <= t; i ++ )
     {
          fin >> x >> y >> z >> a >> b >> c >> n;
          M[1][1]=M[1][3]=M[2][1]=M[2][2]=0;
          M[1][2]=M[2][3]=1;
          M[3][1]=c;
          M[3][2]=b;
          M[3][3]=a;
           
          I3[1][1]=1;I3[2][2]=1;I3[3][3]=1;I3[1][2]=0;I3[1][3]=0;
          I3[2][1]=0;I3[2][3]=0;I3[3][1]=0;I3[3][2]=0;
           
          
          while (n)
          {
                if (n&1) mult1();
                   mult();
                n>>=1;
           }
           
        
 
          fout << ((I3[1][1]*x)%MOD+(I3[1][2]*y)%MOD+(I3[1][3]*z)%MOD)%MOD << "\n";
    }        
                                                                                                                                                                
    return 0;
}
 
                       
 
void mult()
{
     int i,j,l;
     long long S[4][4];
     for (i=1;i<=3;i++)
         for (j=1;j<=3;j++)
         {
             S[i][j]=0;
             for (l=1;l<=3;l++)
                 S[i][j] = (S[i][j]+(M[i][l]*M[l][j])%MOD)%MOD;
         }
 
         for (i=1;i<=3;i++)
             for (j=1;j<=3;j++)
                 M[i][j]=S[i][j];
}
 
void mult1()
{
     int i,j,l;
     long long S[4][4];
     for (i=1;i<=3;i++)
         for (j=1;j<=3;j++)
         {
             S[i][j]=0;
             for (l=1;l<=3;l++)
                 S[i][j] = (S[i][j]+(I3[i][l]*M[l][j])%MOD)%MOD;  
         }
     for (i=1;i<=3;i++)
         for (j=1;j<=3;j++)
             I3[i][j]=S[i][j];
}