/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 12ms 8.07 MiB
#2 Accepted 38ms 8.402 MiB
#3 Accepted 38ms 8.402 MiB
#4 Accepted 37ms 8.398 MiB
#5 Accepted 38ms 8.551 MiB
#6 Accepted 38ms 8.547 MiB
#7 Accepted 39ms 8.402 MiB
#8 Accepted 50ms 8.629 MiB
#9 Accepted 63ms 8.406 MiB
#10 Accepted 91ms 8.547 MiB
#11 Accepted 122ms 8.547 MiB
#12 Accepted 123ms 8.551 MiB
#13 Accepted 123ms 8.551 MiB
#14 Accepted 120ms 8.547 MiB
#15 Accepted 123ms 8.547 MiB
#16 Accepted 124ms 8.551 MiB
#17 Accepted 134ms 8.219 MiB
#18 Accepted 177ms 8.18 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("output1.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 ("input1.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:23:06
Judged At
2024-11-11 03:40:34
Judged By
Score
100
Total Time
177ms
Peak Memory
8.629 MiB