#C13050. Greatest Common Divisor using Euclidean Algorithm
Greatest Common Divisor using Euclidean Algorithm
Greatest Common Divisor using Euclidean Algorithm
In this problem, you are given two integers, and you need to compute their Greatest Common Divisor (GCD) using the Euclidean algorithm. The GCD of two numbers is the largest positive integer that divides each of the integers without leaving a remainder. In case both inputs are 0, output 0. Note that the GCD is always non-negative.
The Euclidean algorithm is implemented by repeatedly replacing the pair (a, b) with (b, a mod b) until b becomes 0. The absolute value of the final result is the GCD of the two numbers.
Example: For input 48 18
, the output is 6
because 6 is the largest number that divides both 48 and 18.
inputFormat
The input consists of a single line, containing two space-separated integers a
and b
.
For example:
48 18
outputFormat
Output a single integer representing the Greatest Common Divisor of a
and b
.
For the above example, the output would be:
6## sample
48 18
6