Cod sursa(job #199723)

Utilizator RobybrasovRobert Hangu Robybrasov Data 20 iulie 2008 12:14:42
Problema Factorial Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.56 kb
const nr=1 shl 30;
var p:longint;
    f:text;

function nr5(x:longint):longint;
var k:longint;
begin
  k:=0;
  while x>0 do begin inc(k,x div 5); x:=x div 5; end;
  nr5:=k;
end;

procedure cb(x:longint);
var i,step:qword;
begin
  step:=nr;
  i:=0;
  while step>0 do
    begin
      if (nr5(i+step)<x) then inc(i,step);
      step:=step shr 1;
    end;
  if nr5(i+1)=p then write(f,i+1) else write(f,-1);
end;

begin
  assign(f,'fact.in');
  reset(f);
  read(f,p);
  close(f);
  assign(f,'fact.out');
  rewrite(f);
  cb(p);
  close(f);
end.