Cod sursa(job #938381)

Utilizator DjokValeriu Motroi Djok Data 12 aprilie 2013 15:11:55
Problema Factorial Scor 95
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.47 kb
 var  n,m,s,p :longint;

begin
 assign(input,'fact.in');
 assign(output,'fact.out');
 reset(input);
 rewrite(output);
 readln(p);
   if p=0 then write('1');

   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(n-1)
              else write('-1');
    
  close(input);
  close(output);
end.