[필수개념]
> 유클리드 호제법을 알고 있어야함
class Solution {
public int[] solution(int n, int m) {
int[] answer = new int[2];
int minnum = Math.min(n,m);
int maxnum = Math.max(n,m);
answer[0] = gcd(maxnum,minnum);
answer[1] = maxnum*minnum/answer[0];
return answer;
}
public int gcd(int a, int b){
if(a%b ==0){
return b;
}
return gcd(b, a%b);
}
}
public class Hello {
public static void main(String[] args) {
Solution test = new Solution();
int o = 2;
int p = 5;
System.out.println(test.solution(o,p));
}
}
'프로그래머 ,백준, 유튜브, 문제' 카테고리의 다른 글
소수 찾기_프로그래머스 (0) | 2022.09.27 |
---|---|
K번째 수_프로그래머스 (0) | 2022.09.27 |
신규아이디 추천_프로그래머스 (0) | 2022.09.27 |
시저암호_프로그래머스 (0) | 2022.09.26 |
소수만들기_프로그래머스 (1) | 2022.09.26 |
댓글