1 solutions

  • 0
    @ 2023-1-21 15:40:35
    #include <bits/stdc++.h> 
    using namespace std;
    int main()
    {
        int n,k,a[10000];
        cin>>n>>k;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        sort(a+1,a+1+n);//用sort函数从小到大排序
        int m=a[n-k+1]-a[k];//求出第k大与第k小的差 !注意:第k大是n-k+1
        bool flag=true;
        for(int i=2;i<m;i++)
        {
            if(m%i==0)
            {
                flag=false;
                break;
            }
        }
        if(flag==true)//判断输出
        {
            cout<<"YES"<<endl<<m;
        }
        else
        {
            cout<<"NO"<<endl<<m;
        }
        return 0;
    }
    
    • 1

    Information

    ID
    582
    Time
    1000ms
    Memory
    32MiB
    Difficulty
    10
    Tags
    # Submissions
    4
    Accepted
    4
    Uploaded By