Cod sursa(job #1631531)

Utilizator medicinedoctoralexandru medicinedoctor Data 5 martie 2016 16:49:36
Problema Factorial Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.59 kb
var y,x,i,p:int64;

function nz(x:int64):int64;
var q:int64;
begin
  q:=0;
  while (x <> 0) do
    if x mod 10 = 0 then q:=q+1 else break;
  nz:=q;
end;

procedure lire;
begin
  assign(input,'fact.in');
  reset(input);
  read(p);
  close(input);
end;

procedure ecrire(x:int64);
begin
  assign(output,'fact.out');
  rewrite(output);
  write(x);
  close(output);
end;

begin
  lire;
  x:=1;
  i:=0;
  y:=trunc(exp(ln(10)*p));
  while (i<>0) do
  begin
    x:=x*i;
    if nz(x)=p then begin ecrire(x); break; end;
    if x>y then x:=x mod y;
    i:=i+1;
  end;
end.