Cod sursa(job #601394)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 6 iulie 2011 13:38:29
Problema Factorial Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.59 kb
Program factorial;
     var n,m,s,p :longint;
         fi, fo:text;
begin
  assign(fi,'fact.in');
   reset(fi);
    read(fi,p);
  assign(fo,'fact.out');
   rewrite(fo);
    if p=0 then begin
                 write(fo,'1');
                 close(fo);
                 exit;
                 end;
   n:=p*4;
   repeat
    m:=5; s:=0;
    while m<=n do begin
                   s:=s+(n div m) ;
                   m:=m*5;
                   end;
     inc(n);
     until (s=p) or (s>p);
  if s=p then
             write(fo,n-1)
              else write(fo,'-1');
   close(fo);
end.