Result: Accepted
Time: 81ms
Memory: 2496kB
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<math.h>
using namespace std;
typedef long long ll;
const int MAXN=1e5+6;
ll a[MAXN];
bool cmp(ll a,ll b)
{
return a>b;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n,cmp);
//for(int i=0;i<n;i++)
//printf("a[i]:%d\n",a[i]);
ll tmp=0,TMP=0;
for(int i=0;i<n;i++)
{
bool flag=false;
for(int j=i+1;j<n;j++)
{
if(a[i]%a[j]!=0)
{
flag=true;
tmp=a[j];
//printf("i:%d,j:%d\n",i,j);
break;
}
}
if(flag)
{
TMP=a[i];
break;
}
}
printf("%lld\n",max(tmp+TMP,a[0]));
//system("pause");
return 0;
}