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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{
  public static void main(String[] args) throws NumberFormatException, IOException
  {
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    while (input.ready())
    {
      String[] dataStr = input.readLine().split(" ");
      int[] dataInt = new int[dataStr.length];
      for (int i = 0; i < dataStr.length; i++)
      {
        dataInt[i] = Integer.valueOf(dataStr[i]);
      }
      System.out.println(getGCD(dataInt[0], dataInt[1]) + " " + getLCM(dataInt[0], dataInt[1]));
    }
  }

  public static int getGCD(int num1, int num2)
  {
    if (num1 == num2)
      return num1;

    int a  = Math.max(num1, num2);
    int b = Math.min(num1, num2);
    int c = 1;

    while (true)
    {
      c = a % b;
      if(c == 0) {
        break;
      }
      a = b;
      b = c;
    }
    return b;
  }

  public static int getLCM(int a, int b)
  {
    int productA = a;
    int productB = b;
    while (productA <= 2000000000)
    {
      if (productA == productB)
      {
        return productA;
      }
      if (productA < productB)
      {
        productA += a;
      }
      else
      {
        productB += b;
      }
    }
    return 0;
  }
}