Cod sursa(job #215622)

Utilizator nod_softwareBudisteanu Ionut Alexandru nod_software Data 19 octombrie 2008 19:09:14
Problema Koba Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.63 kb
program koba;
{$APPTYPE CONSOLE}
uses
  SysUtils;
type nr = record
        x,y,z:Byte;
end;
var
    P,R,x,k,i,j,n,m,rez,a1,a2,a3,a4:Longint;
    t1,t2,t3,t4:byte;
    fin,fout:text;
    v:array [1..10000] of nr;
    LABEL Iesire;
{*----------------------------------*}
begin
        assign(fin,'koba.in'); reset(fin);
        assign(fout,'koba.out'); rewrite(fout);

        read(fin,n,a1,a2,a3);
        T1:=a1 mod 10; T2:=a2 mod 10; T3:=a3 mod 10; k:=0;
        x:=1; V[1].x:=T1; V[1].y:=T2;V[1].z:=T3;

        for i:=1 to n do
        begin
                t4:=t3+t2*t1;
                t4:=t4 mod 10;

                t1:=t2;
                t2:=t3;
                t3:=t4;

                //Verific
                inc(k);
                For j:=1 to x do
                        If (v[j].X=T1) and (v[j].y=T2) and (V[j].z=T3) then
                        Begin
                                Inc(x);
                                V[x].x:=T1;V[x].y:=T2;V[x].z:=T3;
                                P:=j;
                                Goto Iesire;
                        End;
                Inc(x);
                V[x].x:=T1;V[x].y:=T2;V[x].z:=T3;


        end;
        Iesire:
        If i < n then
        Begin
                R:=0; Rez:=0;
                for i:=1 to p-1 do R:=R+V[i].z;
                for i:=p to  x-1 do Rez:=Rez+v[i].z;

                N:=N-p+1;//Scad numerele de nu se repeta....

                R:=R+Rez*(n div (x-p-1));
                for i:=1 to N mod (x-p-1) do R:=R+V[i+p].Z;
        End;
        Writeln(Fout,k);
        Writeln(fout,rez);
        Writeln(Fout,R);

        close(fin);
        close(fout);
end.