#include <iostream>
using namespace std;
long long int Greatest_Common_Divisor(long long int A, long long int B)
{
while(B > 0)
{
long long int tmp = A;
A = B;
B = tmp % B;
}
return A;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
long long int A, B;
cin >> A >> B;
long long int gcd = Greatest_Common_Divisor(A, B);
cout << A * B / gcd;
return 0;
}
Euclidean Algorithm을 이용해 최대공약수를 구하고, 최대 공약수를 이용해 최소공배수를 구하는 알고리즘
'BOJ Review > Algorithms' 카테고리의 다른 글
| [BOJ 11279] MaxHeap (0) | 2023.09.07 |
|---|---|
| [C++ Data Structure] Stack 구현 (0) | 2023.08.31 |