while(true) { String tmp = br.readLine(); if (tmp == null || tmp.isEmpty()) { break; } List list = Arrays.asList(tmp.split(" ")).stream().map(i -> Long.parseLong(i)).sorted().collect(Collectors.toList()); long koyakusu = getKoyakusu(list.get(0), list.get(1)); long kobaisu = getKobaisu(list.get(0), list.get(1)); System.out.printf("%d %d\n", koyakusu, kobaisu); } }
// 公約数の取得 privatestaticlonggetKoyakusu(long a, long b){ long candidate = a; while (b % a != 0) { candidate = b % a; b = a; a = candidate; } return candidate; }
// 公倍数の取得 privatestaticlonggetKobaisu(long a, long b){ return (a * b) / getKoyakusu(a, b); } }