题目链接:点击打开链接
C/C++训练1---最大公约数与最小公倍数
Time Limit: 1000MS
Memory Limit: 65536KB
Problem Description
输入两个整数,求它们的最大公约数与最小公倍数。
Input
输入两个整数,两个整数之间用空格分开。
Output
第一行输出最大公约数;
第二行输出最小公倍数。
第二行输出最小公倍数。
Example Input
64 48
Example Output
16 192
Hint
代码实现:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int m = input.nextInt();
if(n < m){
int t = n;n = m;m = t;
}
int n1 = n;
int m1 = m;
while(m != 0){
int t = n%m;
n = m;
m = t;
}
System.out.println(n);
System.out.println((n1*m1)/n);
}
}