Notice
Recent Posts
Recent Comments
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Today
Total
Archives
관리 메뉴

cyphen156

백준-약수, 배수와 소수 2단계 1934 최소공배수 본문

컴퓨터공학/알고리듬 풀이

백준-약수, 배수와 소수 2단계 1934 최소공배수

cyphen156 2025. 6. 4. 09:49

최소공배수_1934

최소공배수를 구하는데 유클리드 호제법을 사용해서 구해라

제약사항

  • 0 < Test T < 1,000
  • 0 < A, B <= 45,000

주의 사항

없다.

CPP풀이

최소공배수_1934.cpp

/**
 * 백준 최소공배수_1934
 * 최소공배수를 구하는데 유클리드 호제법을 사용해서 구해라
 * 
 * 제한사항
 *****************************************
 * 0 < Test T < 1,000                    *
 * 0 < A, B <= 45,000                    *
 *****************************************
 *
 *
 *
 * 주의
 * 없다.
 * 
 * 풀이시간 5분
 */


#include <iostream>

using namespace std;

int GCD(int A, int B);
int LCM(int A, int B, int GCD);

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t;
    cin >> t;

    for (int i = 0; i < t; ++i)
    {
        int A, B;
        cin >> A >> B;
        cout << LCM(A, B, GCD(A, B)) << '\n';
    }

    return 0;
}

int GCD(int A, int B)
{
    int temp;
    while(B != 0)
    {
        temp = A % B;
        A = B;
        B = temp;
    }
    return A;
}

int LCM(int A, int B, int GCD)
{
    return (A * B) / GCD;
}

모든 예제 코드의 소스파일은 제 개인 깃허브 레포지토리에 있습니다.

 

Workspace/알고리듬 풀이 at main · cyphen156/Workspace

Studying . Contribute to cyphen156/Workspace development by creating an account on GitHub.

github.com