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 static java.lang.System.out;
import static java.lang.Long.parseLong;
import java.io.File;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        new Main().printGCDLCM();
    }

    public void printGCDLCM() {
        try (Scanner scan = new Scanner(System.in)) {
            gcdLCM(scan);
        } catch (Exception e) {
            System.exit(0);
        }
    }

    public void printGCDLCM(String inputDataPath) {
        try (Scanner scan = new Scanner(new File(inputDataPath))) {
            gcdLCM(scan);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void gcdLCM(Scanner scan) {
        String inputData;
        while ((inputData = scan.nextLine()) != null && !"".equals(inputData)) {
            long[] data = getData(inputData);
            out.println(gcd(data) + " " + lcm(data));
        }
    }

    private long[] getData(String inputData) {
        String[] dataSplit = inputData.split(" ");
        long[] data = { parseLong(dataSplit[0]), parseLong(dataSplit[1]) };
        return data;
    }

    private long lcm(long[] data) {
        return (data[0] * data[1]) / gcd(data);
    }

    private long gcd(long[] data) {
        long[] tmpData = changeAB(data).clone();
        long mod = -1;
        while ((mod = tmpData[0] % tmpData[1]) != 0) {
            tmpData[0] = tmpData[1];
            tmpData[1] = mod;
        }
        return tmpData[1];
    }

    private long[] changeAB(long[] data) {
        if (data[0] < data[1]) {
            long tmp = data[0];
            data[0] = data[1];
            data[1] = tmp;
        }
        return data;
    }
}