Cod sursa(job #52064)

Utilizator M@2Te4iMatei Misarca M@2Te4i Data 17 aprilie 2007 18:20:03
Problema Factorial Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.65 kb
var a,z,w,p:int64;
    li,lf:int64;
    //a,z:int64;

{procedure cautare_bin(li,lf:longint);
var i:int64;
begin

a:=(li+lf) div 2;
i:=5;
w:=0;
while a div i>0 do
      begin
      w:=w+a div i;
      i:=i*5;
      end;
end;}

function nrzerouri(a:int64):integer;
var i,q:int64;
begin
i:=5;
q:=0;
while a div i>0 do
      begin
      q:=q+a div i;
      i:=i*5;
      end;
nrzerouri:=q;
end;

procedure cautare;
var gasit:boolean;
begin
li:=1;
lf:=100000000;
gasit:=false;
{if p=0 then
   a:=1
   else begin
        while li<=lf do
              begin
              cautare_bin(li,lf);
              if w=p then
                 begin
                 if not gasit then
                    z:=a
                    else begin
                         if a<z then z:=a;
                         end;
                 gasit:=true;
                 end;
                 if w<p then
                         begin
                         li:=a+1;
                         end
                      else begin
                           lf:=a-1;
                           end;
              end;
        if not gasit then
           a:=-1;
        end;}
while li<=lf do
      begin
      a:=(li+lf)div 2;
      w:=nrzerouri(a);
      if w>=p then
         begin
         if w=p then
            z:=a;
         lf:=a-1;
         end else li:=a+1;
      end;
end;

procedure scriere;
begin
assign(output,'fact.out');
rewrite(output);
write(a);
close(output);
end;

procedure citire;
begin
assign(input,'fact.in');
reset(input);
read(p);
close(input);
end;

begin
citire;
cautare;
scriere;
end.