Cod sursa(job #195631)

Utilizator theratmantheratman theratman Data 20 iunie 2008 11:58:33
Problema Factorial Scor 60
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.58 kb
var f,g:text;
    a,b,c,t,p:longint;
function zero(c:longint):longint;
 var p:longint;
 begin
 zero:=0;
 p:=5;
 while p<=c do begin
  inc(zero,c div p);
  p:=p*5;
  end;
 end;
begin
assign(f,'fact.in');reset(f);
assign(g,'fact.out');rewrite(g);
read(f,p);
if p<>0 then begin
a:=1;
b:=100000000;
t:=0;
while (a<=b) do begin
 c:=(a+b) div 2;
 if zero(c)<p then a:=c+1;
 if zero(c)>p then b:=c-1;
 if zero(c)=p then begin
  writeln(g,c-c mod 5);
  inc(t);
  break;
 end;
end;
if t=0 then writeln(g,'-1');
end;
if p=0 then writeln(g,'1');
close(f);
close(g);
end.