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 C# (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            string temp;
            string[] suuji = new string[2];
            int[] number = new int[2];
            int small,large;
            temp = Console.ReadLine();
            suuji = temp.Split(' ');
            number[0] = int.Parse(suuji[0]);
            number[1] = int.Parse(suuji[1]);
            if (number[0] > number[1])
            {
                small = number[1];
                large = number[0];
            }
            else
            {
                small = number[0];
                large = number[1];
            }
            int remainder;
            while (small != 0)
            {
                remainder = large % small;
                large = small;
                small= remainder;
            }
            Console.WriteLine("{0}", large);
        }
    }
}