We study the exact counting problem for all lattice rectangles contained in the square , including non-axis-parallel ones. Starting from the standard parametrization by a primitive direction and two side lengths, we derive several exact algorithms: the classical sweep, decompositions of complexity and , a ten-moment weighted-floor-sum reduction of complexity , and a divisor-layer algorithm with the complexity . We also give an all-values algorithm that computes in arithmetic operations. The main idea behind the near-linear one-value algorithms is to reduce the geometric summation to constant-size families of weighted floor sums closed under Euclidean-style affine and reciprocal transformations. Besides the exact algorithmic results, we derive a two-term asymptotic expansion, with the explicit formula for , which provides an independent consistency check for the large- numerical data produced by the algorithms.

生成讲解博客的中文版本

生成AI智能校验的中文版本