Cod sursa(job #199721)

Utilizator RobybrasovRobert Hangu Robybrasov Data 20 iulie 2008 12:12:52
Problema Factorial Scor 70
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.58 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,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;
  if rez=x 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.