#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, a[N], b[N], flag = 1;
int main() {
int t = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++) {
if (a[i] != b[t]) {
t++;
b[t] = a[i];
}
}
if (t <= 2) {
cout << "-1";
return 0;
} else {
cout << max(b[t - 2], b[t] % b[t - 1]);
}
}
P5682 [CSP-J2019 江西] 次大值
求助