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: Wrong Answer)

using System;
using System.Collections.Generic;


class Program
{
    static void Main(string[] args)
    {
        Input CInput = new Input();

        int[] input = new int[(int)Input.Define.MAX_ArraySize];

        input = CInput.Line1_int(' ', 2);

        int x = 0, y = 0;
        if (input[0] > input[1])
        {
            x = input[0] % input[1];
            y = input[1];
        }
        else
        {
            x = input[1] % input[0];
            y = input[0];
        }

        int i = x - 1;
        while (true)
        {
            if ((x % i) == 0)
            {
                if ((y % i) == 0)
                {
                    System.Console.WriteLine(i);
                    break;
                }
            }
            i--;
        }
    }
}







class Input
{
    public enum Define
    {
        MAX_ArraySize = 100,
        ArraySize2d = 100,                // 2?¬?????????????[][?] ???????
    }

    public string Line1_string()
    {
        return Console.ReadLine();
    }

    public string[] Line1_string(int chr)
    {
        var input = Console.ReadLine();
        var split = input.Split(' ');
        return split;
    }

    public int Line1_int()
    {
        var input = Console.ReadLine();
        return int.Parse(input);
    }

    public double Line1_double()
    {
        var input = Console.ReadLine();
        return double.Parse(input);
    }

    public int[] Line1_int(int chr, int num)
    {
        var input = Console.ReadLine();
        var split = input.Split(' ');
        int[] spliti = new int[100];
        for (int i = 0; i < num; i++)
        {
            spliti[i] = int.Parse(split[i]);
        }
        return spliti;
    }

    public int[] Multiline_int(ref int datanum)
    {
        int i = 0;
        int[] data = new int[(int)Input.Define.MAX_ArraySize];
        while (true)
        {
            var input = Console.ReadLine();
            var value = int.Parse(input);
            if (value == 0) break;
            data[i] = value;
            i++;
        }
        datanum = i;
        return data;
    }

    /// <summary>
    /// ?????°??????int??????????????????????????????
    /// </summary>
    /// <param name="chr">???????????????</param>
    /// <param name="num">?????????????????????????????°</param>
    /// <param name="datanum">??????????????????????????°</param>
    /// <returns></returns>
    public int[,] Multiline_int(int chr, int num, ref int datanum)
    {
        int i = 0, zerocount = 0;
        int[,] data = new int[(int)Input.Define.MAX_ArraySize, (int)Input.Define.ArraySize2d];
        while (true)
        {
            var input = Console.ReadLine();
            var split = input.Split(' ');
            int[] spliti = new int[100];
            zerocount = 0;
            for (int j = 0; j < num; j++)
            {
                spliti[j] = int.Parse(split[j]);
                if (spliti[j] == 0) zerocount++;
            }
            if (zerocount == num) break;
            for (int j = 0; j < num; j++)
            {
                if (spliti[0] == 0 && spliti[1] == 0) break; // ???????????????????????????
            }
            for (int j = 0; j < num; j++)
            {
                data[i, j] = spliti[j];
            }
            i++;
        }
        datanum = i;
        return data;
    }

    /// <summary>
    /// ?????°??????int??????????????????????????????
    /// </summary>
    /// <param name="chr">???????????????</param>
    /// <param name="num">?????????????????????????????°</param>
    /// <param name="loadnum">???????????????????????°</param>
    /// <returns></returns>
    public int[,] Multiline_int(int chr, int num, int loadnum)
    {
        int i = 0;
        int[,] data = new int[(int)Input.Define.MAX_ArraySize, (int)Input.Define.ArraySize2d];
        while (true)
        {
            if (loadnum == i) break;

            var input = Console.ReadLine();
            var split = input.Split(' ');
            int[] spliti = new int[100];
            for (int j = 0; j < num; j++)
            {
                spliti[j] = int.Parse(split[j]);
            }
            for (int j = 0; j < num; j++)
            {
                data[i, j] = spliti[j];
            }
            i++;
        }
        return data;
    }


}

//??£?¨????????????¬

//int[] input = new int[(int)Input.Define.MAX_ArraySize];
//int[,] input = new int[(int)Input.Define.MAX_ArraySize, (int)Input.Define.ArraySize2d];

class EasyTask
{
    public void Swap(ref int a, ref int b)
    {
        int buf = 0;
        buf = a;
        a = b;
        b = buf;
    }






}