Cod sursa(job #353844)

Utilizator dicu_dariaDaria Dicu dicu_daria Data 6 octombrie 2009 13:58:34
Problema Factorial Scor 25
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.82 kb
program factorial;
var ok:byte;
    f,g:text;
    min,i,e,p,x,y:longint;
begin
assign(f,'fact.in');
reset(f);
assign(g,'fact.out');
rewrite(g);
read(f,p);
i:=0; x:=0; y:=0;
min:=0; e:=0;
while(x<p) do
 begin
 e:=e+2; i:=e;
 ok:=0;
 if (i mod 4=2) then begin x:=x+1; ok:=1; end;
 if ((i-4) mod 8=0) then begin x:=x+2; ok:=1; end;
 if ((i-8) mod 16=0) then begin x:=x+3; ok:=1; end;
 if ok=0 then
 while(i mod 2=0) do
  begin
   x:=x+1;
   i:=i div 2;
  end;
 end;
min:=e; e:=0;
while(y<p) do
 begin
 e:=e+5; i:=e;
 ok:=0;
 if (i mod 5=0) and (i mod 25<>0) then begin ok:=1; y:=y+1; end;
 if ok=0 then
 while(i mod 5=0) do
  begin
   y:=y+1;
   i:=i div 5;
  end;
 end;
if (x>p) and (y>p) then e:=-1;
if e<min then e:=min;
if e=0 then e:=1;
if e<0 then e:=-1;
write(g,e);
close(f);
close(g);
end.