Result: Accepted
Time: 81ms
Memory: 2540kB
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define M 100005
int cmp(const void* p, const void* q){
int* a = (int*)p;
int* b = (int*)q;
int num1 = *a;
int num2 = *b;
return num2>num1;
}
int main(){
int n,i,j,flag=0,si,sj;
long long a[M],fir,sec;
scanf("%d",&n);
for(i=0; i<n; i++){
scanf("%d",&a[i]);
}
qsort(a,n,sizeof(long long),cmp);
fir = a[0];
sec = a[1];
for(i=0; i<n; i++){
for(j=i+1; j<n; j++){
if(a[i]%a[j]!=0 && a[j]%a[i]!=0){
si = i;
sj = j;
flag = 1;
break;
}
}
if(flag==1){
break;
}
}
if(flag==0){
printf("%ld",a[0]);
}else{
printf("%ld",a[si]+a[sj]);
}
}