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

well-life-gm·2021년 12월 21일
0

프로그래머스

목록 보기
102/125

GCD, LCM은 언제든 쓰일 수 있음.

#include <string>
#include <vector>

using namespace std;

int gcd(int a, int b)
{
    if(b == 0)
        return a;
    return gcd(b, a % b);
}
vector<int> solution(int n, int m) {
    vector<int> answer;
    answer.push_back(gcd(n, m));
    answer.push_back(n * m / gcd(n, m));
    return answer;
}
profile
내가 보려고 만든 블로그

0개의 댓글