[JAVA] 최대공약수 GCD, 최소공배수 LCM 기본문법
GCD 최대공약수 int a= 10; int b = 2; BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); System.out.println(gcd.intValue()); 2 LCD 최소공배수 public static int lcm(int x, int y) { //0이 아닌 두 수의 곱 / 두 수의 최대공약수 return (x * y) / gcd(x, y); } private static int gcd(int a, int b) { if(b == 0) { return a; } return gcd(b, a % b); } System.out.println(lcm(a, b..