Modules and imports · 9 / 16 Exercise Medium

Greatest common divisor and least common multiple

Objective

Create a Python program that calculates the greatest common divisor (GCD) and the least common multiple (LCM) of two numbers.

Instructions

  • Read two positive integers, one per line.
  • Calculate the GCD with math.gcd.
  • Calculate the LCM with the formula a · b / GCD (use the integer division //).
  • Show GCD: X on the first line and LCM: Y on the second.
Input
12
18
Output
GCD: 6
LCM: 36

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise