Cod sursa(job #235540)

Utilizator ioalexno1Alexandru Bunget ioalexno1 Data 24 decembrie 2008 13:07:34
Problema Factorial Scor 90
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.73 kb
program alex;
var f,g:text;
    p,h,j,i,d,s,m:longint;
begin
assign(f,'fact.in');reset(f);
readln(f,p);
close(f);
assign(g,'fact.out');rewrite(g);
if p=0 then write(g,1)
       else begin
            i:=1;
            j:=p;
            while(i<=j)and(s<>p)do
                  begin
                  m:=(i+j) div 2;
                  s:=0;
                  h:=1;
                  d:=m*5;
                  while(d div h)<>0 do
                          begin
                          h:=h*5;
                          s:=s+(d div h);
                          end;
                  if s<p then i:=m
                         else j:=m;
                  end;
            write(g,m*5);
            end;
close(g);
end.