suppose we have a grid of 'a' horizontal lines and 'b' vertical lines.
we wish to go from one corner to the diagonally opposite corner along the diagonal.
how many squares do we cross?
the answer is pretty simple. try it!!!
the greater one between a and b, right?
the answer is a + b - gcd(a,b)...
gcd means greatest common divisor...