#K4931. Greatest Common Divisor Using Euclid's Algorithm
Greatest Common Divisor Using Euclid's Algorithm
Greatest Common Divisor Using Euclid's Algorithm
Given two positive integers a and b, your task is to compute their greatest common divisor (gcd). The gcd of two numbers is the largest number that divides both of them without leaving a remainder.
This problem can be solved using Euclid's algorithm, which is based on the mathematical recurrence:
with the base case defined as:
Implement the algorithm to compute the gcd and output the result. The input is provided via standard input (stdin) and the output must be printed to standard output (stdout).
inputFormat
The input consists of a single line containing two integers a and b separated by a space. Both integers are positive and will fit in a 32-bit signed integer.
outputFormat
Output a single integer, which is the greatest common divisor of a and b.
## sample48 18
6