Cod sursa(job #1631550)

Utilizator medicinedoctoralexandru medicinedoctor Data 5 martie 2016 16:55:25
Problema Factorial Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.65 kb
var y,x,i,p:int64;
b:boolean;

function nz(x:int64):int64;
var q:int64;
begin
  q:=0;
  while (x <> 0) do
    if x mod 10 = 0 then begin q:=q+1; x:=x div 10; end 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;
  b:=false;
  x:=1;
  i:=1;
  y:=trunc(exp(ln(10)*p));
  while (i<>0) do
  begin
    x:=x*i;
    b:=nz(x)=p;
    if b then ecrire(i);
    if b then break;
    if x>y then x:=x mod y;
    i:=i+1;
  end;
end.