>>910 面倒なので最小限の修正で import java.io.*; public class Test3 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int a = Integer.parseInt(br.readLine()); int b = Integer.parseInt(br.readLine()); int koyaku = gcd(a, b); int kobai = (int)((long)a * b / koyaku); System.out.println("最大公約数は" + koyaku); System.out.println("最小公倍数は" + kobai); } private static int gcd(int a, int b) { while (true) { int c = a % b; if (c == 0) return b; a = b; b = c; } } }