Cod sursa(job #628976)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 2 noiembrie 2011 15:17:29
Problema Factorial Scor 100
Compilator fpc Status done
Runda gc_practice Marime 0.51 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.