counting number of square unit the line should travel

88 Views Asked by At

Imagine the first quadrant of the real plane as consisting of unit squares. A typical square has $4$ corners: $(i,j)$, $(i+1,j)$, $(i+1,j+ 1)$, and $(i,j+1)$, where $(i,j)$ is a pair of non-negative integers. Suppose a line segment $l$ connecting $(0,0)$ to $(90,1100)$ is drawn. We say that $l$ passes through a unit square if it passes through a point in the interior of the square. How many unit squares does $l$ pass through?

I have searched many website but not getting proper explanation of the solution. The answer of this question is $1180$.

1

There are 1 best solutions below

3
On

The first step is to work out how many grid points it goes through. For example, it goes through (9,110). The numbers 9 and 11 have no common factor, so there isn't any other grid point between (0,0) and (9,11) that it goes through.

The line therefore goes through the points (0,0), (9,110), (18,220), ... (90,1100). The 10 sections between successive grid points look exactly the same, so if we work out how many squares it goes through in one section, the whole line goes through exactly 10 times as many.

So lets look at one 9 by 110 section. The line goes vertically a distance of 110. Therefore it crosses over vertically to a new square 109 times. Similarly, it enters a new square horizontally 8 times. These horizontal/vertical crossings never happen simultaneously, because that would make the line go through another grid point, and we already made sure this is a section of the line between grid points. So after the first (0,0) square, it enters 109+8=117 new squares for a total of 118.

The whole line therefore goes through 118*10=1180 squares.