#K36042. Max Square Tiles
Max Square Tiles
Max Square Tiles
You are given a rectangle of height H and width W. The task is to find the maximum number of equal-sized square tiles that can completely cover the rectangle without overlapping. The side length of the square tile must be a factor of both dimensions of the rectangle.
Let \( g = \gcd(H, W) \). Then the side of the largest possible square tile is \( g \), and the number of square tiles required is given by: \[ \frac{H}{g} \times \frac{W}{g} \]
For example, if H=6
and W=9
, then \( g=3 \) and the number of square tiles is \( (6/3) \times (9/3)=2\times3=6 \).
inputFormat
The input consists of two space-separated integers: H
(the height of the rectangle) and W
(the width of the rectangle). These numbers are provided via standard input (stdin).
outputFormat
Output a single integer representing the maximum number of equal-sized square tiles that can cover the rectangle completely. The result should be printed to standard output (stdout).
## sample6 9
6