SNOOKER - Snooker
Consider a rectangular snooker table with pockets only at the 4 corners of the rectangle as shown in the image below. Consider all integer points on the boundary of the table. At each point, except the four corners (four pockets), you are allowed to hit the ball at an angle of 45 degrees from the side of the table from which you are hitting the ball.
From any point on the boundary you can hit the ball in two directions and they are considered to be two different ways. For instance in the image shown below, from the point S the ball can be hit in two ways as shown.
Given the dimensions of the board your task is to find the number of ways in which the ball can be hit so that it eventually reaches one of the four holes.
Consider the ball to be of negligible size, like a point. Also assume that the ball does not lose energy due to collisions or friction - it keeps moving until it drops into a hole.
The input has multiple test cases. Each test case consists of two space separated integers M and N, 2 ≤ M,N ≤ 10^5, representing the dimensions of the table. M=N=0 indicates the end of tests. There are atmost 300 testcases.
For each test case output the number of ways as described, in a separate line.
Input: 2 2 2 4 3 5 0 0 Output: 0 4 24
Tedious to code this one.
this is a simple application of school-level geometry................