Cod sursa(job #308215)

Utilizator frozen62iceBLue FirE frozen62ice Data 26 aprilie 2009 14:13:44
Problema Factorial Scor 95
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.81 kb
const max=100000000;
var f,g:text;
    p:longint;
function verif(m:longint):longint;
 var nr:longint;
 begin
  nr:=5;
  verif:=0;
  while nr<=m do begin
   inc(verif,m div nr);
   nr:=nr*5;
  end;
 end;
procedure caut_binar(st,dr:longint);
 var m,v:longint;
 begin
  while st<dr do begin
   m:=(st+dr)div 2;
   v:=verif(m);
   if v>p then caut_binar(st,m-1)
    else
   if v<p then caut_binar(m+1,dr)
    else begin
     while verif(m)=p do dec(m);
     writeln(g,m+1);
     close(f);
     close(g);
     halt;
    end;
  end;
  if st>=dr then begin
    writeln(g,'-1');
    close(f);
    close(g);
    halt;
   end;
 end;
begin
assign(f,'fact.in');reset(f);
assign(g,'fact.out');rewrite(g);
read(f,p);
if p=0 then writeln(g,'0')
 else caut_binar(1,5*(p+1));
close(f);
close(g);
end.