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)

#include<stdio.h>
#define DATA 100

int main(){
	int a[DATA], b[DATA];
	int i, j, k, tmp1, tmp2;
	int GCD[DATA], LCM[DATA];

	i = 0;
	while (scanf("%d %d", &a[i], &b[i]) != EOF)
		i++;

	for (j = 0; j < i; j++){
		if (a[j] < b[j]){
			for (k = a[j]; k >= 2; k--){
				if (a[j] % k == 0 && b[j] % k == 0){
					GCD[j] = k;
					break;
				}
				if (k == a[j])
					if (k % 2 == 0)
						k = k / 2;
					else
						k = k / 2 + 1;
			}
		}
		else{
			for (k = b[j]; k >= 2; k--){
				if (a[j] % k == 0 && b[j] % k == 0){
					GCD[j] = k;
					break;
				}
				if (k == b[j])
					if (k % 2 == 0)
						k = k / 2;
					else
						k = k / 2 + 1;
			}
		}

		tmp1 = a[j];
		tmp2 = b[j];
		while (a[j] < 2000000000 && b[j] < 2000000000){
			if (a[j] < b[j]){
				a[j] += tmp1;
			}
			else if (b[j] < a[j]){
				b[j] += tmp2;
			}
			if (a[j] == b[j]){
				LCM[j] = a[j];
				break;
			}
		}
		printf("%d %d\n", GCD[j], LCM[j]);
	}

	return 0;
}