Practice

Greatest Common Divisor

HARDAlgorithms

Read two positive integers. Output their Greatest Common Divisor (GCD) using the Euclidean algorithm.

Input: Two positive integers on separate lines. Output: The GCD.

Example:

Input:  12
        8
Output: 4

Sample Test Cases

Test 1: GCD(12, 8)
Inputs: 12, 8
Expected: 4
Test 2: GCD(100, 75)
Inputs: 100, 75
Expected: 25
Test 3: Coprime
Inputs: 7, 13
Expected: 1

Premium Question

This question needs a paid plan — upgrade, or join a class from a teacher who has one. You can read the description and sample tests, but grading is locked.

Sign in to get started