#include <iostream> #include <vector> #include <stack> #include <queue> #include <cstdlib> #include <cmath> #include <string> #include <sstream> #include <iterator> #include <algorithm> #include <numeric> using namespace std; int f(int n) { if(n<2) { return 0; } for(int i=2;i*i<=n;i++) { if(n%i==0) { return 0; } } return 1; } int main() { int n,k; vector<int> v; cin>>n>>k; int num; for(int i=0;i<n;i++) { cin>>num; v.push_back(num); } sort(v.begin(),v.end()); int m1=v[k-1]; sort(v.rbegin(),v.rend()); int m2=v[k-1]; if(f(m2-m1)==1) { cout<<"YES"<<endl; cout<<m2-m1<<endl; } else { cout<<"NO"<<endl; cout<<m2-m1<<endl; } return 0; }
解题思路:
注意事项:
参考代码:
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:732 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:669 |
ASCII帮了大忙浏览:752 |
printf基础练习2 (C语言代码)浏览:943 |
母牛的故事 (C语言代码)浏览:959 |
妹子杀手的故事 (C语言代码)浏览:1241 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:460 |
C语言程序设计教程(第三版)课后习题7.5 (C语言代码)浏览:528 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:546 |
WU-蓝桥杯算法提高VIP-企业奖金发放 (C++代码)浏览:1179 |