Result: Accepted
Time: 70ms
Memory: 3376kB
#include<cstdio>
#include<cmath>
#include<string.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
#include<string>
#include<stdlib.h>
using namespace std;
const int p=0x3f3f3f3f;
#define maxn 100005
long long a[maxn],b[maxn];
int n,m,k,x,y,l,r;
char s[maxn];
int gcd(int a,int b)
{
return b==0?a:gcd(b,gcd(b,a%b));
}
int cmp(int a,int b)
{
return a>b;
}
int main()
{
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
scanf("%lld",&a[i]);
sort(a,a+n,cmp);
long long sum=a[0];
for(int i=0;i<n/2;i++)
{
if(a[0]%a[i]!=0)
{
sum+=a[i];
break;
}
else if(a[0]%a[n-1-i]!=0)
{
sum+=a[n-1-i];
break;
}
}
printf("%lld\n",sum);
}
}