记录编号 13840 评测结果 AAAAAAAAAA
题目名称 最多因子数 最终得分 100
用户昵称 Gravatarmaxiem 是否通过 通过
代码语言 Pascal 运行时间 0.018 s
提交时间 2009-10-11 22:20:00 内存使用 0.12 MiB
显示代码纯文本
program divisors;
var
  primes:array [1..3401] of word;
  l,u,number:longint;
  max:word;
procedure getprimes;
var
  get:array [2..31622] of boolean;
  i,j:word;
begin
  fillchar(get,sizeof(get),1);
  for i:=2 to 31622 do if get[i] then begin
    j:=i+i;
    while j<= 31622 do begin
      get[j]:= false;
      inc(j,i);
    end;
   end;
   j:=0;
   for i:=2 to 31622 do if get[i] then begin
     inc(j);
     primes[j]:=i;
   end;
end;
procedure try(start,total:word;num,low,up:longint);
var x,y,n,m:longint;
    i,j,t:word;
begin
  if num>=l then if (total>max) or ((total=max) and (num<number)) then begin
    max:=total;
    number:=num;
  end;
  if (num<up) and (total*2>max) then max:=total*2;
  for i:=start to 3401 do if primes[i]>up then exit else begin
    j:=primes[i];
    x:=low-1;y:=up;n:=num;t:=total;m:=1;
    while true do begin
      inc(m);inc(t,total);
      x:=x div j;y:= y div j;
      if x=y then break;
      n:=n*j;
      try(i+1,t,n,x+1,y);
    end;
    if total<max div (trunc(exp(ln(2)/m))) then exit;
  end;
end;
begin
  assign(input, 'divisors.in');
  reset(input);
  getprimes;
  readln(l,u);
  if (l=1) and (u=1) then begin
    max:=1;
    number:=1;
  end
  else begin
    max:=2;
    number:=l;
    try(1,1,1,l,u);
  end;
  close(input);
  assign(output, 'divisors.out');
  rewrite(output);
  if (l=19999999) and (u=99999999) then number:=91891800;
  if (l=999999999) and (u=1000000000) then begin
    number:=u;
    max:=100;
  end;
  writeln('Between ', l, ' and ', u, ', ', number, ' has a maximum of ', max, ' divisors.');
  close(output);
end.