本文共 452 字,大约阅读时间需要 1 分钟。
输入两个正整数m和n,求其最大公约数和最小公倍数
输入 34 8 输出 2 136import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); System.out.println(gcd(m, n) + " " + m * n / gcd(m, n)); } static int gcd(int a, int b) { while(b != 0) { int t = b; b = a % b; a = t; } return a; }}
转载地址:http://hktkx.baihongyu.com/