/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 27ms 320.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;

/// .................... type def
using ll = long long;
using ull = unsigned long long;
using ld = long double;

const ll N = 1e5+5;
int prime[N];
void seive(ll n){
    n+=2;
    int sqn = sqrt(n)+1;
    for(int i=4;i<=n;i+=2) prime[i]=1;
    for(int i=3;i<=sqn;i+=2){
        if(prime[i]==1) continue;
        for(int j=i+i;j<=n;j+=i) prime[j]=1;
    }
}

int popcount(ll x)
{
    int cnt=0;
    for(int i=0;i<64;i++) if((x&(1ull<<i))!=0) ++cnt;  return cnt;   
}
bool cmp(pair<int,int>a, pair<int,int>b)
{
    if(a.second==b.second)
    {
        return a.first>b.first;
    }
    return a.second<b.second;
}
void solve()
{
    int n; cin>>n;
    vector<pair<int,int>>v(n);
    for(int i=0;i<n;i++) cin>>v[i].first;
    int k; cin>>k;
    int num,cnt=0,rt;
    for(int i=0;i<n;i++)
    {
        cnt=2;
        int num = v[i].first;
        rt = sqrt(num)+1;
        if(num==2)
        {
            v[i].second=2;
            continue;
        }
        if(num==1)
        {
            v[i].second=1;
            continue;
        }
        for(int i=2;i<rt;i++)
        {
            if(num%i==0)
            {
                if(i==num/i) cnt++;
                else cnt+=2;
            }
        }
        v[i].second=cnt;
    }

    sort(v.begin(),v.end(),cmp);
    //for(auto x:v) cout<<x.first<<" "<<x.second<<endl; cout<<endl;
    cout<<v[k-1].first<<endl;
}


int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int t; cin>>t; while(t--) solve();
}

Information

Submit By
Type
Submission
Problem
P1008 Ordering Number
Contest
Beta Round #1
Language
C++17 (G++ 13.2.0)
Submit At
2023-11-29 16:46:28
Judged At
2024-11-11 03:50:50
Judged By
Score
100
Total Time
27ms
Peak Memory
320.0 KiB