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

#include <bits/stdc++.h>

using namespace std;

#define N 100010

int n;
int arr[N];
vector<int> G[N];
int Stk[N], top;

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

int main() {
	scanf("%d", &n);
	int ans = 0;
	set<int>s;
	for (int i = 1; i <= n; ++i) {
		scanf("%d", arr + i);
		ans = max(arr[i], ans);
		s.insert(arr[i]);
	}
	sort(arr + 1, arr + 1 + n);
	for (int i = n; i >= 1; --i) {
		for (int j = i - 1; j >= 1; --j) {
			int G = gcd(arr[i], arr[j]);
			if (G != arr[i] && G != arr[j]) {
				ans = max(ans, arr[i] + arr[j]);
				break;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}