Cod sursa(job #677982)

Utilizator Buzu_Tudor_RoCont vechi Buzu_Tudor_Ro Data 10 februarie 2012 21:02:53
Problema Factorial Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.96 kb
Program P1_fact;
var n,y,z,k : longint;
    fi,fo : text;

begin n:=0;
      assign(fi,'fact.in'); reset(fi); readln(fi,y);
      assign(fo,'fact.out'); rewrite(fo); z:=0;

      if y=0 then write(fo,'1')
             else begin
                  n:=4*y;
                  n:=n-(n mod 5);
                  k:=5;
                  while (k<=n) do begin
                                  z:=z + (n div k);
                                  k:=k*5;
                                  end;
                  repeat
                       if z<y then n:=n+5;
                       k:=n;
                       while k mod 5=0 do begin
                                          z:=z+1;
                                          k:=k div 5;
                                          end;
                  until z>=y;

                  if z=y then write(fo,n)
                         else write(fo,-1);
                  end;
      close(fi); close(fo);
end.