Cod sursa(job #329693)

Utilizator ionutz32Ilie Ionut ionutz32 Data 7 iulie 2009 09:45:23
Problema Factorial Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.64 kb
var p,a,b,m,c,r:longint;
f,g:text;
function fc(x:longint):longint;
         var nr:longint;
         begin
         nr:=0;
         while x div 5<>0 do
               begin
               nr:=nr+x div 5;
               x:=x div 5;
               end;
         fc:=nr;
         end;
begin
assign(f,'fact.in');
assign(g,'fact.out');
reset(f);rewrite(g);
read(f,p);
a:=1;b:=2147483640;
while a<=b do
      begin
      m:=(a+b) div 2;
      c:=fc(m);
      if c>=p then
         b:=m-1
      else
          if c<p then
             a:=m+1;
      end;
if fc(b+1)=p then
   write(g,b+1)
else
    write(g,-1);
close(f);close(g);
end.