최대공약수, 최소공배수 구하는 문제이다.
내생각엔 long long을 써야될것 같은데 int로 해도 통과된다.
GCD는 유클리드 호제법으로 풀었고 LCM은 GCD로 구했다.
#include <algorithm>
#include <vector>
using namespace std;
int GCD(int a, int b)
{
if (b == 0)
return a;
else
return GCD(b, a % b);
}
vector<int> solution(int n, int m) {
vector<int> answer;
int gcd = GCD(n, m);
int lcm = n * m / gcd;
answer.push_back(gcd);
answer.push_back(lcm);
return answer;
}'Coding_Test 연습 > Programmers' 카테고리의 다른 글
| [프로그래머스] (C++) LV1 평균 구하기 (0) | 2022.04.27 |
|---|---|
| [프로그래머스] (C++) LV1 콜라츠 추측 (0) | 2022.04.27 |
| [프로그래머스] (C++) LV1 짝수와 홀수 (0) | 2022.04.27 |
| [프로그래머스] (C++) LV1 제일 작은 수 제거하기 (0) | 2022.04.27 |
| [프로그래머스] (C++) LV1 정수 제곱근 판별 (0) | 2022.04.27 |