#K4931. Greatest Common Divisor Using Euclid's Algorithm

    ID: 28614 Type: Default 1000ms 256MiB

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:

gcd(a,b)=gcd(b,amodb)\gcd(a, b) = \gcd(b, a \mod b)

with the base case defined as:

gcd(a,0)=a\gcd(a, 0) = a

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.

## sample
48 18
6