Problem:
GCD and LCM

Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b.

Input

Input consists of several data sets. Each data set contains a and b separated by a single space in a line. The input terminates with EOF.

Constraints

0 < a, b ≤ 2,000,000,000

LCM(a, b) ≤ 2,000,000,000

The number of data sets ≤ 50

Output

For each data set, print GCD and LCM separated by a single space in a line.

Sample Input

8 6
50000000 30000000

Output for the Sample Input

2 24
10000000 150000000

Solution in C# (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;

namespace Problem0005
{
    class Problem0005
    {
        static void Main(string[] args)
        {
            var inputPairs =
                GetInputLines()
                .Select(line => line.Split().Select(word => int.Parse(word)).ToArray());
            foreach (int[] pair in inputPairs)
            {
                int n1 = pair[0];
                int n2 = pair[1];
                int gcd = GetGCD(n1, n2);
                int lcm = n1 * n2 / gcd;
                Console.WriteLine(gcd.ToString() + " " + lcm.ToString());
            }
        }

        static int GetGCD(int n1, int n2)
        {
            int leastCommonFactor =
                Enumerable.Range(2, Math.Min(n1, n2) - 1)
                .FirstOrDefault(n => n1 % n == 0 && n2 % n == 0);
            if (leastCommonFactor != 0)
            {
                return leastCommonFactor * GetGCD(n1 / leastCommonFactor, n2 / leastCommonFactor);
            }
            else
            {
                return 1;
            }
        }

        static IEnumerable<string> GetInputLines()
        {
            string line;
            while (!string.IsNullOrEmpty(line = System.Console.ReadLine()))
            {
                yield return line;
            }
        }
    }
}