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: 3264kB
In contest: 1276

#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<cmath>
#include<cctype>
#include<algorithm>
#include<cstdio>
using namespace std;
vector<long long> a;
long long gcd(long long x, long long y) {
	if(x == y)
		return x;
	int r = x % y;
	while(r) {
		x = y;
		y = r;
		r = x % y;
	}
	return y;
}
bool cmp(long long x, long long y) {
	return x > y;
}
int main(){
	int n;
	cin >> n;
	int i, j;
	long long z;
	for(i = 0; i < n; i++) {
		cin >> z;
		a.push_back(z);
	}
	sort(a.begin(), a.end(), cmp);
	long long max;
	for(i = 0; i < a.size(); i++) {
		if(i == 0)
			max = a[0];
		for(j = i + 1; j < a.size(); j++) {
			if(gcd(a[i], a[j]) == 1 && a[i] + a[j] > max)
				max = a[i] + a[j];
		}
		if(a[i] <= max / 2)
			break;
	}
	cout << max;
	return 0;

}