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 PHP (judge verdict: Wrong Answer)

<?php

// ??´??° x, y ???????????????x ??\ y ????????° 
// x ??¨ y ????????§??¬?´???°??? y ??¨ x % y ????????§??¬?´???°???????????????
    $nums = trim(fgets(STDIN));
    $array = explode(' ',$nums);
    $small_num = $array[0] > $array[1] ? $array[1] : $array[0];
    $big_per_small = ($array[0] > $array[1] ? $array[0] : $array[1]) % $small_num;
    $small_num_cp = $big_per_small;
    while (true) {
        if ($big_per_small == 0) {
            echo $small_num_cp, PHP_EOL;
            break;
        } 
        if ((($big_per_small % $small_num_cp) == 0) && (($small_num % $small_num_cp) == 0)) {
            echo $small_num_cp, PHP_EOL;
            break;
        } else $small_num_cp--;
    }