#K68652. Largest Square Grid Side
Largest Square Grid Side
Largest Square Grid Side
Given a rectangular garden with dimensions n and m, you are to determine the side length of the largest square grid that can be laid out inside the garden. Each square in the grid should be of the same size, and the grid should utilize the maximum possible area without exceeding the garden's boundaries.
The key observation is that the side length of the largest square grid is equal to the greatest common divisor (GCD) of n and m. In mathematical terms, the answer is given by: \(s = \gcd(n, m)\).
For example, if the garden dimensions are 10 and 15, then \(\gcd(10,15)=5\); hence the side length of each square in the grid would be 5.
inputFormat
The input consists of two space-separated integers n and m representing the dimensions of the garden, provided via standard input.
Input Format: n m
outputFormat
Output a single integer: the side length of the largest square grid that can be arranged within a garden of dimensions n and m.
Output Format: s## sample
10 15
5