Accepted
Code
#include<bits/stdc++.h>
using namespace std;
const long long M=2e6+10,MOD=1000000007;
typedef long long ll;
ll fre[M];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while(t--){
int n,x;
cin>>n>>x;
vector<int>v(n);
int limit=0;
for(auto &i:v){
cin>>i;
fre[i]++;
limit=max(i,limit);
}
ll mx=1e18;
int k=1;
for(int i=1;i<=x;i++){
ll cost=0;
for(ll j=i;j<=limit;j+=i){
cost+=(fre[j]*j);
}
if(cost==0){
k=i;
break;
}
if(cost<mx){
mx=cost;
k=i;
}
}
cout<<k<<"\n";
for(int i:v)fre[i]=0;
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1039 Prince Roy, the undisputed ruler of the world
- Language
- C++20 (G++ 13.2.0)
- Submit At
- 2024-05-02 18:39:44
- Judged At
- 2024-11-11 03:35:57
- Judged By
- Score
- 100
- Total Time
- 30ms
- Peak Memory
- 1.184 MiB