Result: Accepted
Time: 68ms
Memory: 1368kB
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
bool cmp(const int &a,const int &b){
return a>b;
}
int gcd(int x,int y){
if(y==0) return x;
gcd(y,x%y);
}
int main(){
int n;
scanf("%d",&n);
int sum[100005];
for(int i=1;i<=n;i++){
scanf("%d",&sum[i]);
}
sort(sum+1,sum+n+1,cmp);
int ans1,ans2,max=0;
ans1=sum[1];
for(int i=2;i<=n;i++){
if(sum[i]!=gcd(ans1,sum[i])){
ans2=sum[i];
break;
}
}
max=ans1+ans2;
printf("%d\n",max);
}