#P10415. Maximum Equal-Sized Square Partition
Maximum Equal-Sized Square Partition
Maximum Equal-Sized Square Partition
Given a \(W \times H\) rectangle with integer sides, the task is to cut the rectangle into many smaller squares. These squares must have integer side lengths and be of the same size, with the side length at least \(2\). The cutting process is assumed to have no loss, and no leftover material is allowed. Determine the maximum number of such squares that can be obtained.
In other words, if a square of side length \(s\) (where \(s \ge 2\)) is chosen, then in order to cover the entire rectangle without waste, \(s\) must be a common divisor of both \(W\) and \(H\). The number of squares will be \(\frac{W \times H}{s^2}\). Find the \(s\) (with \(s \ge 2\)) that maximizes this number. If no valid \(s\) exists, output \(0\).
inputFormat
The input consists of two integers \(W\) and \(H\) separated by a space, representing the width and height of the rectangle, respectively.
outputFormat
Output a single integer: the maximum number of equal-sized squares that can be cut from the rectangle. If it is not possible to cut the rectangle as required, output \(0\).
sample
10 6
15