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: 98ms
Memory: 25156kB
In contest: 1276

#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;
}