JXNVCE ALGO-LOG YouJin Jung

BOJ-1934

유클리드를 이용한 최소공배수 구하기 방식! 최대공약수를 활용한다.

#include<iostream>
 
using namespace std;
 
int divide(int x, int y) {
    if (x%y==0) return y;
    else return divide(y, x%y);
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    int T, A, B;
    cin >> T;
 
    for (int i=0; i<T; i++) {
        cin >> A >> B;
        if (A>=B) {
            cout << A*B/divide(A,B) << "\n";
        }
        else
            cout << A*B/divide(B,A) << "\n"; 
    }
    return 0;
}