링크
https://www.acmicpc.net/problem/1037
양수 A가 N의 진짜 약수가 되려면, N이 A의 배수이고, A가 1과 N이 아니어야 한다. 어떤 수 N의 진짜 약수가 모두 주어질 때, N을 구하는 프로그램을 작성하시오.
첫째 줄에 N의 진짜 약수의 개수가 주어진다. 이 개수는 50보다 작거나 같은 자연수이다. 둘째 줄에는 N의 진짜 약수가 주어진다. 1,000,000보다 작거나 같고, 2보다 크거나 같은 자연수이고, 중복되지 않는다.
첫째 줄에 N을 출력한다. N은 항상 32비트 부호있는 정수로 표현할 수 있다.
2
4 2
8
1
2
4
6
3 4 2 12 6 8
24
14
14 26456 2 28 13228 3307 7 23149 8 6614 46298 56 4 92596
185192
#include <stdio.h>
#include <stdlib.h>
int compare(const void* first, const void* second)
{
int a = *(const int*)first;
int b = *(const int*)second;
if (a < b)
return -1;
else if (a > b)
return 1; //내림차순 정렬
else
return 0;
}
int main()
{
int N;
int* arr;
int result;
scanf("%d", &N);
arr = (int*)malloc(sizeof(int) * N);
for (int i = 0; i < N; i++)
scanf("%d", &arr[i]);
qsort(arr, N, sizeof(arr[0]), compare); //퀵 정렬
result = arr[0] * arr[N - 1]; //1과 자기 자신을 제외한 약수 중 가장 작은 약수와 가장 큰 약수의 곱
printf("%d", result);
free(arr);
return 0;
}