Cod sursa(job #199715)

Utilizator RobybrasovRobert Hangu Robybrasov Data 20 iulie 2008 12:04:44
Problema Factorial Scor 90
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.83 kb
const nr=1 shl 30;
var p,k,i,rez:longint;
    n:qword;
    f:text;
{
function nr5(x:longint):longint;
var p,k,i,cn:longint;
begin
  i:=5; k:=0;
  while i<=x do
    begin
      p:=0;
      cn:=i;
      while cn mod 5=0 do begin cn:=cn div 5; inc(p); end;
      inc(k,p);
      inc(i,5);
    end;
  nr5:=k;
end;
}
function nr5(x:longint):longint;
var cn,k:longint;
begin
  k:=0;
  while x>0 do begin inc(k,x div 5); x:=x div 5; end;
  nr5:=k;
end;

function cb(x:longint):int64;
var i,step,rez:qword;
begin
  step:=nr;
  i:=0;
  while step>0 do
    begin
      rez:=nr5(i+step);
      if (rez<x) then inc(i,step);
      step:=step shr 1;
    end;
  cb:=i+1;
end;

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