Result: Accepted
Time: 98ms
Memory: 25156kB
#include<bits/stdc++.h>
using namespace std;
const int maxn = 3000050;
typedef long long ll;
ll a[maxn];
ll n;
ll Max = 0;
int gcd(int a,int b){
if(b == 0) return a;
else return gcd(b,a%b);
}
int main(){
cin>>n;
for(int i = 1 ; i <= n ; i++){
scanf("%lld",&a[i]);
Max = max(a[i],Max);
}
sort(a+1,a+n+1,greater<int>());
for(int i = 1 ; i <= n ;i++){
if(a[i] + a[i + 1] <= Max) break;
for(int j = i + 1 ; j <= n ; j++){
if(a[i] != gcd(a[i],a[j]) && a[j] != gcd(a[i],a[j])) Max = max(Max,a[i]+a[j]);
}
}
printf("%d",Max);
return 0;
}