#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include <cmath>
#include <algorithm>
using namespace std;
bool isPrime(int x)
{
bool flag = true;
for(int i = 2; i <= sqrt(x); ++i)
if(x % i == 0)
{
flag = false;
return false;
}
return true;
}
int a[10005];
int main()
{
int n, k;
int m;
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
sort(a+1, a+1+n);
m = a[n-k+1]-a[k];
if(m < 2)
{
cout << "NO" << endl;
cout << m << endl;
}
else
{
if(isPrime(m))
{
cout << "YES" << endl;
cout << m << endl;
}
else
{
cout << "NO" << endl;
cout << m << endl;
}
}
return 0;
}
tyvj p1001- 第K极值[模拟]
最新推荐文章于 2019-12-05 18:55:06 发布