Cod sursa(job #303422)

Utilizator frozen62iceBLue FirE frozen62ice Data 9 aprilie 2009 20:34:01
Problema Factorial Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.66 kb
const max=100;
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:longint;
 begin
  while st<dr do begin
   m:=(st+dr)div 2;
   if verif(m)>p then caut_binar(st,m-1)
    else
   if verif(m)<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;
 end;
begin
assign(f,'factorial.in');reset(f);
assign(g,'factorial.out');rewrite(g);
read(f,p);
caut_binar(1,max);
end.