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;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] inputA = input.Split();
            int[] inputi = new int[2];
            inputi[0] = int.Parse(inputA[0]);
            inputi[1] = int.Parse(inputA[1]);
            int n;
            if (inputi[0] > inputi[1])
            {
                n = inputi[0] % inputi[1];
            }
            else if (inputi[0] < inputi[1])
            {
                n = inputi[0] % inputi[1];
            }
            else
            { 
                n = inputi[0];
            }
            int gcd = 0;
            for (int i = 1; i < n; i++)
            {
                if (n % i == 0)
                    gcd = i;
            }
            Console.WriteLine(gcd);
            Console.ReadLine();

            //string sN = Console.ReadLine();
            //int N = int.Parse(sN);
            //string st = Console.ReadLine();
            //string[] ast = st.Split();
            //int[] A = new int[ast.Length];
            //for (int n = 0; n < N; n++)
            //{
            //    A[n] = int.Parse(ast[n]);

            //}
            //int key;
            //int j;
            //for (int i = 0; i < A.Length; i++)
            //{
            //    if (i != 0)
            //    {
            //        key = A[i];
            //        /* insert A[i] into the sorted sequence A[0,...,j-1] */
            //        j = i - 1;
            //        while (j >= 0 && A[j] > key)
            //        {
            //            A[j + 1] = A[j];
            //            j--;
            //        }
            //        A[j + 1] = key;
            //    }

            //    string output = "";

            //    for (int ii = 0; ii < A.Length; ii++)
            //    {

            //        output += A[ii] + " ";
            //    }
            //    output = output.TrimEnd(' ');
            //    Console.WriteLine(output);

            //}
            //Console.ReadLine();
        }
    }
}