Problem 434610 · easy · Level 04 Non-Linear Data Structures

Largest Square Tile for a Floor

recursion · gcd · modulo

A tiler wants to cover a rectangular floor of size w by h (whole centimetres) with identical square tiles and no cutting. Write tile_size(w, h) returning the side length of the largest square tile that fits exactly, using a recursive definition (no math.gcd, no loops). If both sides are 0, return 0.

Examples

Input:  w = 48, h = 18
Output: 6
Explanation: 6 divides both 48 and 18 and nothing bigger does.

Input:  w = 7, h = 0
Output: 7

Constraints

  • 0 <= w, h <= 10**15
  • Recursion depth is at most ~75 for these sizes.

Goals

  • Reduce a pair of numbers with the remainder operation
  • Recognise that a zero second argument ends the recursion
  • Return the first argument at the base case
Starting Python…