| 
 | 
back to boardWA#12 what is wrong this function? function calc(x, y, l ,r: int64): int64;   var n, nx, ny: int64;     n1,n2: int64;   begin      if l < x then l := x;      if x > r then begin        result := 0;        exit;       end;       if ( x = 1 ) then begin        result := (r - l + 1);        exit;     end;      if x = y then begin        result := ( r div x - ((l-1) div x) );        exit;      end;    if y + 1 >= x + x then begin       result := (r - l + 1);       exit;    end;         n := (y - 2) div ( y - x ) + 1;     while  (y * (n - 1) + 1 >= x * n) and (n > 0) do dec(n);     if n * x  <= l then begin      result := (r - l + 1);      exit;   end;   result := 0;   if n*x <= r then begin      result := r - n*x + 1;      r:=n*x - 1;   end;           nx := (l + y - 1) div y;       if nx*x > r then begin         result := result + 0;         exit;       end;       ny := r div x;       if ny * y < l then begin          result := result +0;          exit;       end;       if ( ny * x <= l ) and (ny*y >= r)then begin         result := result +r - l + 1;         exit;       end;       if ( nx * x <= l ) and (nx*y >= r)then begin         result := result +r - l + 1;         exit;       end;         if (ny * y < l ) and ( ny * x + x > r) then begin        result := result +(0);        exit;      end;     if nx = ny then begin        if l < nx * x then l := nx * x;        if r > nx * y then r := ny * y;        result := result +(r - l + 1);        exit;      end;        if l < nx * x then l := nx * x;      if r > nx * y then r := ny * y;        n1 := nx + 1;      n2 := ny - 1;      if n1 <= n2 then          result := result + (n2 - n1 + 1) + (y-x) * (( n1+n2) * (n2-n1+1) div 2);      result := result + nx * y - l + 1  + (r - ny*x + 1);
 
    end;  |  
  | 
|