Problem:
Greatest Common Divisor

Write a program which finds the greatest common divisor of two natural numbers a and b

Input

a and b are given in a line sparated by a single space.

Output

Output the greatest common divisor of a and b.

Constrants

1 ≤ a, b ≤ 109

Hint

You can use the following observation:

For integers x and y, if x ≥ y, then gcd(x, y) = gcd(y, x%y)

Sample Input 1

54 20

Sample Output 1

2

Sample Input 2

147 105

Sample Output 2

21

Solution in Rust (judge verdict: Accepted)

fn main() {
    let stdin = std::io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    let vec: Vec<&str> = buf.split_whitespace().collect();
    let mut a: Vec<u32> = vec.iter().map(|&x| x.parse().unwrap_or(0)).collect();
    let mut gcd = 1;
    let mut d = 2;
    loop {
        if a[0] == 1 || a[1] == 1 {
            break;
        } else if a[0] % d == 0 && a[1] % d == 0 {
            a[0] /= d;
            a[1] /= d;
            gcd *= d;
            d = 2;
        } else if a[0] == d || a[1] == d {
            break;
        } else {
            d += 1;
        }
    }
    println!("{}", gcd);
}