解题思路: 先求最大公约数,再求最小公倍数
import java.util.Scanner; public class C1011 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { F(sc.nextInt(), sc.nextInt()); } sc.close(); } private static void F(int a, int b){ if(a == b){ System.out.printf("%d\n%d", 1, a); } int m = Math.max(a, b), n = Math.min(a, b); int k = 0; while((k = m % n) != 0){ m = n; n = k; } System.out.printf("%d\n%d", n, a*b/n); } }
注意事项:
参考代码:
0.0分
0 人评分