Cod sursa(job #1127847)

Utilizator paulabenbendea paula paulaben Data 27 februarie 2014 14:04:30
Problema Iepuri Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.25 kb
const cst=666013;
 
type matr=array[1..3,1..3]of int64;
 
var a:array[1..3,1..3]of int64;
    t1,t2:array[1..3,1..3]of int64;
    x,y,z,t,ti:longint;
    n:longint;
 
procedure putere(n:longint);
  var k:matr; i,j,z:byte;
  begin
    if n=1 then
      begin
        a:=t2;
      end
    else
      begin
        putere(n div 2);
        for i:=1 to 3 do
          for j:=1 to 3 do t1[i,j]:=0;
 
        for i:=1 to 3 do
          for j:=1 to 3 do
            for z:=1 to 3 do t1[i,j]:=(t1[i,j]+(a[i,z]*a[z,j])mod cst)mod cst;
        if ((n mod 2)=1) then
          begin
            for i:=1 to 3 do
              for j:=1 to 3 do
                begin
                  a[i,j]:=0;
                  for z:=1 to 3 do a[i,j]:=(a[i,j]+(t1[i,z]*t2[z,j])mod cst)mod cst;
                end;
          end else a:=t1;
      end;
  end;
 
begin
  assign(input,'iepuri.in'); reset(input);
  assign(output,'iepuri.out'); rewrite(output);
  readln(t);
  for ti:=1 to t do
    begin
      readln(x,y,z,t2[1,1],t2[1,2],t2[1,3],n);
      t2[2,1]:=1; t2[2,2]:=0; t2[2,3]:=0; t2[3,1]:=0; t2[3,2]:=1; t2[3,3]:=0;
      putere(n-2);
      writeln(((a[1,1]*z)mod cst + (a[1,2]*y)mod cst + (a[1,3]*x)mod cst)mod cst);
    end;
  close(output);
end.