코드
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
// 최대 공약수
int gcd(int a, int b)
{
if(a == 0) return b;
return gcd(b % a, a);
}
// 최소 공배수
int lcm(int a, int b)
{
return a * b / gcd(a, b);
}
int main()
{
cout << gcd(5, 20) << "\n";
cout << lcm(5, 20) << "\n";
return 0;
}
/*
5
20
*/
'알고리즘 > 기본 문법' 카테고리의 다른 글
<알고리즘> 에라토스테네스의 체 (0) | 2022.04.21 |
---|---|
<알고리즘> 모듈러 연산 (0) | 2022.04.21 |
<알고리즘> 조합(Combination) (0) | 2022.04.21 |
<알고리즘> 순열(permutation) (0) | 2022.04.21 |
<알고리즘> 구조체를 이용한 커스텀 정렬 (0) | 2022.04.19 |