Cod sursa(job #262783)

Utilizator FllorynMitu Florin Danut Flloryn Data 19 februarie 2009 17:22:09
Problema Koba Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.99 kb
program pascal;
var f,g:text;   t1,t2,t3,x,aux1,aux2,aux3:integer; sum,poz:int64; n,i:longint;
    a:array[0..100000] of longint;

  procedure citire;
  begin
  assign(f,'koba.in'); reset(f);
  assign(g,'koba.out'); rewrite(g);
  read(f,n,t1,t2,t3);
  t1:=t1 mod 10; t2:=t2 mod 10; t3:=t3 mod 10;
  aux1:=t1; aux2:=t2; aux3:=t3;
  close(f);
  end;

  procedure me;
  begin
  sum:=0; poz:=0;
  for i:=1 to n do
    begin
      x:=(t3+t2*t1) mod 10;
      sum:=sum+x;
      t1:=t2;
      t2:=t3;
      t3:=x;
      if (t1=aux1) and (t2=aux2) and (t3=aux3) then
                  begin
                  poz:=i;
                  break;
                  end;
     a[i]:=a[i-1]+x;
    end;
  if poz<>0 then
       begin
       t1:=n div poz;
       sum:=sum*t1;
       if t1 mod poz<>0 then
               begin
               poz:=t1*poz;
               sum:=sum+a[n-poz+1];
               end;
       end;

  end;

begin
citire;
me;
write(g,sum);
close(g);
end.