Cod sursa(job #108862)

Utilizator loriKis Levente Lorand lori Data 23 noiembrie 2007 23:44:58
Problema Factorial Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.53 kb
var P,N,i,aux,s:longint;
begin
 assign(input,'fact.in'); reset(input);
 assign(output,'fact.out'); rewrite(output);
  readln (P);
  if P=0 then writeln ('1')
         else begin
   N:=P*4; aux:=N;
   while aux>=5 do begin
    s:=s+aux div 5; aux:=aux div 5;
   end;
   i:=s; N:=N-N mod 5;
   while p>i do begin
    N:=N+5; aux:=N;
    while (aux mod 5=0) and (aux<>0) do begin
     i:=i+1; aux:=aux div 5;
    end;
   end;
   if P=i then writeln (N)
          else writeln ('-1');
  end;
  close(input); close(output);
end.