공부기록/프로그래머스

[프로그래머스] 최대공약수와 최소공배수

메델 2024. 2. 3. 00:19
import java.util.*;
import java.math.*;
class Solution {
    public int[] solution(int n, int m) {
        
        BigInteger bigN = new BigInteger(Integer.toString(n));
        BigInteger bigM = new BigInteger(Integer.toString(m));
        
        BigInteger gcd =  bigN.gcd(bigM);
        BigInteger lcm = bigN.multiply(bigM).divide(gcd);
        
        int[] answer = {gcd.intValue(), lcm.intValue()};
        
        return answer;
    }
}

 

이렇게 풀라고 낸 문제는 아닌 것 같은데

있는건 써야..