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: Accepted)

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

namespace v0_0005
{
    class Program
    {
        static List<int> div = new List<int>() { 2 };

        static void Main(string[] args)
        {
            string line;
            while (!string.IsNullOrEmpty(line = Console.ReadLine()))
            {
                var ab = line.Split(' ');
                var a = int.Parse(ab[0]);
                var b = int.Parse(ab[1]);
                int LCM = 1;
                int GCD = 1;

                int divVal;
                while ((divVal = GetDivisor(a, b)) != -1)
                {
                    a /= divVal;
                    b /= divVal;
                    GCD *= divVal;
                }
                LCM = GCD * a * b;

                Console.WriteLine("{0} {1}", GCD, LCM);
            }
        }

        static int GetDivisor(int a, int b)
        {
            foreach (var d in div)
            {
                if ((a % d == 0) && (b % d == 0)) { return d; }
            }

            int st = div.Min() + 1;
            for (int i = (st % 2 == 0) ? st + 1 : st; i <= Math.Max(a, b); i += 2)
            {
                if ((a % i == 0) && (b % i == 0))
                {
                    if (!div.Contains(i)) { div.Add(i); }
                    return i;
                }
            }
            return -1;
        }
    }
}