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

백준-심화 2 1037 약수

cyphen156 2025. 7. 10. 09:20

약수

1과 N을 제외한 N의 약수를 모두 줄 때 원래 수 N을 구하시오

제약사항

  • InputCount is Divisor Count - 2
  • 0 < InputCount <= 50
  • 2 <= Input <= 1,000,000

주의 사항

없다.

CPP풀이

약수_1037.cpp

/**
 * 백준 약수_1037
 * 1과 N을 제외한 N의 약수를 모두 줄 때 원래 수 N을 구하시오
 * 
 * 제한사항
 *****************************************
 * InputCount is Divisor Count - 2       *
 * 0 < InputCount <= 50                  *
 * 2 <= Input <= 1,000,000               *
 *****************************************
 *
 *
 *
 * 주의
 * 없다.
 * 
 * 풀이시간 5분
 */


#include <iostream>

#define MAX_VALUE   1000001
#define MIN_VALUE   1

using namespace std;

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

    cin >> inputCount;

    int divisors[2];

    divisors[0] = MAX_VALUE;
    divisors[1] = MIN_VALUE;

    for (int i = 0; i < inputCount; ++i)
    {
        int input;
        cin >> input;
        
        if (divisors[0] > input)
        {
            divisors[0] = input;
        }

        if (divisors[1] < input)
        {
            divisors[1] = input;
        }
    }

    N = divisors[0] * divisors[1];
    cout << N << '\n';
    return 0;
}

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

 

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

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

github.com