알고리즘

[알고리즘] 백준 2702 - 초6 수학 (C++)

blueberrysoda 2024. 9. 19. 23:45

[문제 링크] : https://www.acmicpc.net/problem/2702

#include <iostream>
using namespace std;

int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int main(){
    int T, A, B, G;
    cin >> T;

    while(T--){
        cin >> A >> B;
        G = gcd(A, B);
        cout << (A * B) / G << " " << G << "\n";
    }
    return 0;
}