Start: Jun, 28, 2019 08:42:00
2019杭州师范大学第一届程序设计竞赛新生赛
End: Jun, 28, 2019 11:42:00
Time elapsed:
Time remaining:

Problem_ID: H
Result: Accepted
Time: 162ms
Memory: 7128kB
In contest: 1276

#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<cmath>
using namespace std;
#define maxn 100010
#define ll long long
#define mm(a,b) memset(a,b,sizeof(a))
int n;
ll a[maxn];
map<int,int>m;
int main()
{
	cin>>n;
	for(int i=0;i<n;++i)
	{	
		scanf("%lld",&a[i]);
		m[a[i]]=1;
	}
	sort(a,a+n);
	n=unique(a,a+n)-a;
	ll ans=a[n-1];
	for(int i=n-1;i>0;--i)
	{
		for(int j=i-1;a[j]+a[i]>ans;--j)
		{
			if(a[i]%a[j]&&a[j]%a[i]) {ans=a[i]+a[j]; break;}
		}
	}
	cout<<ans;
}