给定2个正整数,求它们的最大公约数和最小公倍数,并输出。
输入格式:
输入有若干组。
每组数据,在一行中给出两个正整数M和N(≤1000),中间有1个空格。
输出格式:
对于每组输入,在一行中顺序输出M和N的最大公约数和最小公倍数,两数字间以1个空格分隔。
输入样例:
18 12
20 15
39 26
5 76
45 25
1993 343
输出样例:
在这里给出相应的输出。例如:
6 36
5 60
13 78
1 380
5 225
1 683599
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
int m,n,cs1,cs2,ys,t,x,y;
cs1 = 0;
cs2 = 0;
Scanner sc = new Scanner(System.in);
while(sc.hasNextInt()) {
ys = 1;
m = sc.nextInt();
n = sc.nextInt();
//System.out.println(m+""+n);
if(m>n) {
cs1 = m;cs2 = n;
} else if(m<n) {
cs1 = n;cs2 = m;
}
//System.out.println(cs1+""+cs2);
while(ys!=0) {
ys = cs1%cs2;
cs1 = cs2;
cs2 = ys;
}
x = cs1;
y = m*n/x;
System.out.println(x+" "+y);
}
}
}