Classic algorithms · 13 / 22 Exercise Easy

Greatest common divisor

Objective

Create a Python program that computes the greatest common divisor of two numbers with the Euclidean algorithm.

Instructions

  • Read two positive integers a and b, one per line.
  • While b is not 0: add 1 to the steps and do a, b = b, a % b.
  • When it finishes, the GCD is a. Show GCD: X on the first line and Steps: K on the second.
Input
48
18
Output
GCD: 6
Steps: 3

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

Start exercise