Result: Accepted
Time: 83ms
Memory: 2108kB
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <functional>
#include <fstream>
using namespace std;
const int maxn=1e5+10;
const int inf=0x3f3f3f3f;
typedef long long LL;
int gcd(int x,int y){
if(x<y)
swap(x,y);
return y==0?x:gcd(y,x%y);
}
int n,arr[maxn];
int main()
{
scanf("%d",&n);
for(int i=0;i<n;++i)
scanf("%d",&arr[i]);
n=unique(arr,arr+n)-arr;
sort(arr,arr+n,greater<int>());
int ans=*max_element(arr,arr+n);
for(int i=0;i<n;++i){
for(int j=i+1;j<n;++j)
if(gcd(arr[i],arr[j])==1&&arr[i]!=1&&arr[j]!=1){
ans=max(ans,arr[i]+arr[j]);
break;
}
if(arr[i]*2<=ans)
break;
}
cout<<ans<<endl;
}