LCM1 [알고리즘] 최대공약수(GCD), 최소공배수(LCM) - JAVA 최대공약수(GCD)GCD는 Greatest Common Divisor의 약자로 최대공약수이다. 두 수의 약수들의 공통된 값 중 최댓값을 말한다. GCD를 구하는 방법을 알아보자. 1. BigInteger 내장 함수private static int gcd(int a, int b) { BigInteger n = BigInteger.valueOf(a); BigInteger m = BigInteger.valueOf(b); return n.gcd(m).intValue();}2. 재귀private static int gcd(int a, int b) { if(b == 0) { return a; } return gcd(b, a % b);}3. 반복문private static.. 2024. 5. 18. 이전 1 다음