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: WA: Presentation Error)

<?php

class Solver
{
    private $num_x;
    private $num_y;

    public function __construct()
    {
        while (1) {
            $line = fgets(STDIN);
            if ($line == false) {
                break;
            }
            $line = trim($line);
            $lines[] = $line;
        }

        $num_xy = explode(' ', $lines[0]);
        $this->num_x = $num_xy[0];
        $this->num_y = $num_xy[1];
    }

    public function getAnswer()
    {
        echo $this->calculateGCD($this->num_x, $this->num_y);
    }

    public function calculateGCD($x, $y)
    {
        list($x, $y) = $x > $y ? [$x, $y] : [$y, $x];

        $candidate = $x % $y;
        if (($this->num_x % $candidate) + ($this->num_y % $candidate) >0) {
            return $this->calculateGCD($y, $candidate);
        }
        else {
            return $candidate;
        }
    }
}

$answer = new Solver;
$answer->getAnswer();