Problem 3

Compute a greatest common divisor (GCD) between two positive integers x and y.

Please note:

  1. If x is greater-equal y and x is divisible by y, the GCD between x and y is y.

  2. Otherwise, the GCD between x and y is GCD(y, x % y).

For x == 36 and y == 44, the GCD is 4.

Do not use math.gcd function.

Functions:

gcd(x, y)

Compute the greatest common divisor (GCD) between x and y.

gcd(x: int, y: int) int[source]

Compute the greatest common divisor (GCD) between x and y.

Requires
  • y > 0

  • x > 0

Ensures
  • result == math.gcd(x, y)