Cod sursa(job #138565)

Utilizator ioalexno1Alexandru Bunget ioalexno1 Data 18 februarie 2008 20:45:40
Problema Koba Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.02 kb
program alex;
var f:text;
    s,j,n,c,r,i,p,w,y:longint;
    e:boolean;
    t:array[1..100000]of integer;
begin
assign(f,'koba.in');reset(f);
readln(f,n,t[1],t[2],t[3]);
close(f);
s:=(t[1] mod 10)+(t[2] mod 10)+(t[3] mod 10);
assign(f,'koba.out');rewrite(f);
j:=3;
e:=true;
repeat
j:=j+1;
t[j]:=((t[j-1]mod 10)+(t[j-2]mod 10)*(t[j-3]mod 10))mod 10;
s:=s+t[j];
for i:=1 to j-3 do
    if(t[i]=t[j-2])and(t[i+1]=t[j-1])and(t[i+2]=t[j])then begin
                                                          e:=false;
                                                          p:=i;
                                                          end;
until(j=n)or(e=false);
if e=false then begin
                w:=0;
                for y:=p to j-3 do
                    w:=w+t[y];
                c:=(n-p+1)div(j-p-2);
                s:=s+w*c-w-t[j]-t[j-1]-t[j-2];
                r:=(n-p+1)mod(j-p-2);
                for y:=p to p+r-1 do
                    s:=s+t[y];
                end;
writeln(f,s);
close(f);
end.