过了,但是求hack原来的代码
查看原帖
过了,但是求hack原来的代码
747732
sunpengyu楼主2024/10/1 17:35

15pts15pts

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=2e5+7;
int n,a[maxn],l=1,r=LONG_LONG_MIN,ans=LONG_LONG_MIN,num;
bool jud(int x){
	num=0;
	for(int i=1;i<=n;i++){
		if(a[i]%x==0){
			num++;
		}
	}
	if(num<2) return false;
	return true;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		r=max(r,a[i]);
	} 
	while(l<r){
		int mid=l+(r-l>>1);
		if(jud(mid)) l=mid+1,ans=max(ans,mid*num);
		else r=mid-1;
	}
	cout<<ans;
	return 0;
}
2024/10/1 17:35
加载中...