这道题弄了很久,好不容易看懂了题解,是用分解质因数+乘法原理,结果写出来的程序还是超时,程序还是太弱了...先贴上来,以后再重新写过

program son;
type
  arr=array[1..500] of longint;
var
  data,a0,a1,b0,b1:arr;
  x0,y0,x1,y1,n,len,ans,k:longint;
procedure first;
var
  i,j:longint;
begin
  len:=2;
  data[1]:=2;
  data[2]:=3;
  for i:=5 to y1 do
  begin
    j:=1;
    while (j<=len) and (i mod data[j]<>0) do inc(j);
    if j=len+1 then
    begin
      inc(len);
      data[len]:=i;
    end;
  end;
end;
procedure work(var a:arr;k:longint);
var
  i:longint;
begin
  for i:=1 to len do
  begin
    if data[i]>k then break;
    while (k>0) and (k mod data[i]=0) do
    begin
      inc(a[i]);
      k:=k div data[i];
    end;
  end;
end;
procedure suan;
var
  i,l,r:longint;
begin
  for i:=1 to len do
    if (a0[i]<>0) or (a1[i]<>0) or (b0[i]<>0) or (b1[i]<>0) then
    begin
      if (a1[i]>a0[i]) or (b1[i]<b0[i]) then
      begin
        writeln('0');
        {close(input);
        close(output);}
        halt;
      end;
      if (a1[i]=a0[i]) or (b1[i]=b0[i]) then
      begin
        if a1[i]=a0[i] then l:=a1[i];
        if b1[i]=b0[i] then r:=b1[i];
      end;
      if (a1[i]<a0[i]) or (b1[i]>b0[i]) then
      begin
        if a1[i]<a0[i] then l:=a1[i];
        if b1[i]>b0[i] then r:=b1[i];
      end;
      if (r<l) or (a1[i]<a0[i]) and (b1[i]>b0[i]) and (l<>r) then
      begin
       writeln('0');
       {close(input);
       close(output);}
       halt;
      end;
      if r-l>0 then ans:=ans*(r-l);
    end;
end;
begin
  assign(input,'son.in');
  reset(input);
  assign(output,'son.out');
  rewrite(output);
  readln(n);
  for k:=1 to n do
  begin
    fillchar(a0,sizeof(a0),0);
    fillchar(a1,sizeof(a1),0);
    fillchar(b0,sizeof(b0),0);
    fillchar(b1,sizeof(b1),0);
    readln(x0,x1,y0,y1);
    first;
    work(a0,x0);
    work(a1,x1);
    work(b0,y0);
    work(b1,y1);
    ans:=1;
    suan;
    writeln(ans);
  end;
  close(input);
  close(output);
end.