/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 8ms 852.0 KiB
#3 Accepted 8ms 792.0 KiB
#4 Accepted 8ms 960.0 KiB
#5 Accepted 8ms 832.0 KiB
#6 Accepted 8ms 788.0 KiB
#7 Accepted 8ms 836.0 KiB
#8 Accepted 8ms 948.0 KiB
#9 Accepted 9ms 788.0 KiB
#10 Accepted 10ms 1.004 MiB
#11 Accepted 11ms 1.18 MiB
#12 Accepted 12ms 1.062 MiB
#13 Accepted 11ms 1.07 MiB
#14 Accepted 11ms 1.02 MiB
#15 Accepted 12ms 1.066 MiB
#16 Accepted 11ms 1.184 MiB
#17 Accepted 13ms 856.0 KiB
#18 Accepted 30ms 816.0 KiB

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