/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 26ms 8.156 MiB
#2 Accepted 35ms 8.414 MiB
#3 Accepted 36ms 8.402 MiB
#4 Accepted 35ms 8.41 MiB
#5 Accepted 36ms 8.406 MiB
#6 Accepted 37ms 8.41 MiB
#7 Accepted 38ms 8.484 MiB
#8 Accepted 43ms 8.355 MiB
#9 Accepted 52ms 8.402 MiB
#10 Accepted 71ms 8.547 MiB
#11 Accepted 93ms 8.398 MiB
#12 Accepted 93ms 8.531 MiB
#13 Accepted 93ms 8.551 MiB
#14 Accepted 93ms 8.551 MiB
#15 Accepted 94ms 8.543 MiB
#16 Accepted 94ms 8.551 MiB
#17 Accepted 103ms 8.246 MiB
#18 Accepted 145ms 8.199 MiB

Code

/*
 *   Copyright (c) 2024 Emon Thakur
 *   All rights reserved.
 */
#include<bits/stdc++.h>
using namespace std;
using ll=long long;

vector<int> divv[1000005];
void seive()
{
    for(int i=2;i<=1000000;i++)
    {
        for(int j=i+i;j<=1000000;j+=i) divv[j].push_back(i);
    }
}

void solve()
{
    int n; cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    long long ans[10005]={0};
    for(int i=0;i<n;i++)
    {
        for(auto e:divv[a[i]])
        {
            ans[e] += a[i];
        }
        ans[a[i]] += a[i];
        if(a[i]!=1) ans[1]+= a[i];
    }

    long long anss = 1e18;
    for(int i=1;i<=100000;i++)
    {
        if(ans[i]!=0) anss = min(anss,ans[i]);
    }
    //for(int i=1;i<=10;i++) cout<<ans[i]<<" ";
    cout<<anss<<endl;
}

//ofstream file("output0.txt");
void solve2()
{
    int n,x; cin>>n>>x;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    vector<ll>ans(1000001);

    int sq;
    for(int i=0;i<n;i++)
    {
        sq = sqrt(a[i]);
        for(int ii=1;ii<=sq;ii++)
        {
            if(a[i]%ii) continue;
            if(ii==(a[i]/ii))
            {
                ans[ii] += a[i];
            }
            else
            {
                ans[ii] += a[i];
                ans[a[i]/ii] += a[i];
            }
        }
    }

    ll sum = ans[x];
    int sol=x;
    for(int i=x;i>=1;i--)
    {
        if(ans[i]<=sum)
        {
            sol = i;
            sum = ans[i];
        }
    }

    //for(int i=1;i<=x;i++) cout<<ans[i]<<" ";
    cout<<sol<<endl;
    //file<<sol<<endl;
}

int main()
{
    //seive();
    
    //freopen ("input19.txt","r",stdin);
    int t; cin>>t; while(t--) solve2();
}

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-03-20 17:16:53
Judged At
2024-11-11 03:40:37
Judged By
Score
100
Total Time
145ms
Peak Memory
8.551 MiB