Artificial intelligent assistant

number of rectangles in two superimposed grids I got two grids consisting of square "pixels", each has a different unit length per pixel though, 1 and $\frac1\xi$. Now I superimpose them as in the following image. The grid sizes differ, as illustrated in the image. Due to the ceiling the grid with more pixels usually overlaps, but this can be neglected and it can be assumed that it does not overlap. Now the question is, how many different rectangles do I have after superimposing? Like, assume the two superimposed grids to be one and count the resulting rectangles in it. What is the mathematical approach/explanation to get the amount of the rectangles?

It is enough to consider what happens on one side, i.e. count the number of intervals. The number of rectangles will be the product of the numbers vertically and horizontally (consider the Cartesian product).

In the case that $m$ and $m'=\lceil\xi m\rceil$ are relative primes, there are $m+m'-1$ intervals, because there are $m+1$ and $m'+1$ bounds respectively, and the two extreme coincide.

When the pixel counts aren't relative primes, the bounds coincide periodically, $\gcd(m,m')+1$ times.

Hence, there are

$$(m+m'-\gcd(m,m'))(n+n'-\gcd(n,n'))$$ rectangles.

In the given example, $(8+15-1)^2=484$.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 548caa280978d2be66b7b2b8e355a3d1