3
$\begingroup$

If we have an $a\times b$ rectangle divided into unit squares with $L$ being a diagonal of the rectangle, how many of the unit squares that it contains also contain a point of $L$?

I initially started working with smaller cases and tried to form a generalisation. I struggled to find the link and after searching online came across the following: Total no. of squares containing diagonal = $a + b - \gcd(a,b)$.

But I would really like to improve my understanding of why it is so. May I please have some help with clarifying why we incorporate the gcd?

Thank you!

  • 0
    Have you tried a few different little rectangles, and drawn the results, and counted? What have *you* tried so far?2017-01-18
  • 0
    See also http://math.stackexchange.com/questions/1121541/number-of-unit-squares-that-meet-a-given-diagonal-line-segment-in-more-than-one2017-01-18
  • 0
    Exactly that. I tried cases for several rectangles and it held every time. Initially for the first few cases I concluded it was a + b -1 but found it didn't hold for certain other cases. a + b - gcd(a,b) appears to hold for all cases but I'm just struggling with the intuition as to why it is so2017-01-18
  • 0
    In the case your question is motivated by some kind of segment drawing. In this case, have you heard about Bresenham line algorithm (https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm)?2017-01-18

1 Answers 1

1

Imagine 'stairstepping' up from the bottom-left corner of your rectangle to the top-right. $a+b$ (really, $a+b-1$; the endcaps here are a little awkward) represents the number of grid squares you'd have to cross (whatever your path) if every step that you take has to step across the edge of a square.

But you have the potential to take short-cuts; every time the diagonal goes through a lattice point, you can skip diagonally from one square to the next on your path. Can you show that there are $\gcd(a,b)$ (again, more accurately, $\gcd(a,b)-1$) of these?