Number of unit squares that meet a given diagonal line segment in more than one point Let $l$, $b$ be positive integers. Divide the $l \times b$ rectangle into $lb$ unit squares in the usual manner. Consider one of the two diagonals of this rectangle. How many of these unit squares contains a segment of positive length of this diagonal?
 A: The diagonal line will cross $b$ squares (in the $b$ direction) and $l$ squares (in the ($l$ direction), These ($b$ and $l$ directions) will count separately toward the total number of squares cut except for $\gcd(l,b)$ occasions when the diagonal makes the transition from one row to the next in both directions through a grid point. This counts the start/end corners as "half a grid point" each, by analogy with the $2b \times 2l$ rectangle. 
Thus the total number of squares with a portion of the diagonal will be $l+b-\gcd(l,b)$.

For the illustration, $l=8, b=12$ and the diagonal goes through $\gcd(12,8)=4$ grid points for a total of $12+8-4=16$ squares cut.
A: Calling the requested number $f(l,b)$, and putting $d=\gcd(l,b)$, one has $f(l,b)=d f(\frac ld,\frac bd)$. This is because cutting the diagonal into $d$ pieces of equal length, the subdivision points are lattice points (in fact they are precisely the lattice points on the diagonal), and all $d$ pieces are similar.
This reduces the problem to the case where $l,b$ are relatively prime. Now there are no intermediate lattice points, so every time the diagonal passes from a previous square into a new square, it either does so horizontally or vertically, but not both. Now use the fact that you pass into a new square horizontally $l-1$ times in all, and vertically $b-1$ times in all. That makes for $1+(l-1)+(b-1)=l+b-1$ squares in all, the initial $1$ counting the square one is in before passing to a new square for the first time.
For the general case one then finds 
$$f(l,b)=d f(\frac ld,\frac bd)=d(\frac ld+\frac bd-1)=l+b-d, \qquad\text{where $d=\gcd(l,b)$.}
$$
A: Having read multiple answers, I could not help myself help report that there is a very elementary approach to an answer.
The first step is to compute the slope. Which is $s = b/l$,  if the ratio is irreducible to simple fractions, then you must walk $l$ steps forward to get an integer $b$. Then, $gcd(b,l) = 1$, but for now, this is only mathematical jargon which, to me side steps from the actual elementary argument.
Coming back to the above, the act of walking $l$ steps to get to $b$ means you have not encountered any vertices of any square by walking $1, 2,3,4,...,l-1$ steps. You will encounter a vertex at the very end.
