40pts help
查看原帖
40pts help
551630
Lemon_zqp楼主2023/10/10 21:16
#include<bits/stdc++.h>
#define int long long
using namespace std;

int a[200005];
bool if_c[1000000000];

signed main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	int maxn = -1, max2n = -1, cnt = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			int t = a[i] % a[j];
			if(t  > maxn){
			max2n = maxn;
			maxn = t;
			}
			if(!if_c[t]){
				cnt++;
				if_c[t] = true;
			}
		}
		
	}
	if(cnt < 2){
		cout << -1;
	}
	else{
		cout << max2n;
	}
	return 0;
}

2023/10/10 21:16
加载中...