http://codevs.cn/problem/1979/

时间限制: 1 s
 空间限制: 1000 KB
 题目等级 : 黄金 Gold
 查看运行结果
 
 
题目描述 Description

给定一个长度为N(0<n<=10000)的序列,保证每一个序列中的数字a[i]是小于maxlongint的非负整数 ,编程要求求出整个序列中第k大的数字减去第k小的数字的值m,并判断m是否为质数。(0<k<=n)

输入描述 Input Description

第一行为2个数n,k(含义如上题)
第二行为n个数,表示这个序列

输出描述 Output Description

如果m为质数则
第一行为'YES'(没有引号)
第二行为这个数m
否则 
第一行为'NO'
第二行为这个数m

样例输入 Sample Input
5 2
1 2 3 4 5
样例输出 Sample Output
YES
2
数据范围及提示 Data Size & Hint

20%数据满足0<n<=10
50%数据满足0<n<=5000
100%数据满足0<n<=10000

排序+素数

 #include <algorithm>
#include <cstdio> using namespace std; #define LL long long
LL n,k,a[+],ans; bool jud(LL x)
{
for(LL i=;i*i<=x;i++)
if(x%i==) return ;
return ;
}
bool cmp(LL a,LL b)
{
return a>b;
} int main()
{
scanf("%lld%lld",&n,&k);
for(int i=;i<=n;i++) scanf("%lld",a+i);
sort(a+,a+n+);
ans-=a[k];
sort(a+,a+n+,cmp);
ans+=a[k];
if(ans<||!jud(ans)) printf("NO\n");
else printf("YES\n");
printf("%lld",ans);
return ;
}

最新文章

  1. Spring aop应用之实现数据库读写分离
  2. How to make your assembly more secure from referencing by unauthorized bits
  3. 利用Dockerfile构建一个基于centos 7,包括java 8, tomcat 7,php ,mysql+mycat的镜像
  4. Tcl
  5. 利用jQuery和CSS实现环形进度条
  6. 数据库 SQL语句小结(更新中)
  7. CentOS设置防火墙开放端口
  8. tp5中的一些小方法
  9. Android的onCreateOptionsMenu()创建菜单Menu详解
  10. WinHex分析PE格式(2)&amp;&amp; 如何手动添加区段并运行区段
  11. HTTP层 &mdash;&mdash; Session
  12. [Docker] Install Docker on Windows (hp) and start with Kitematic
  13. 如何高效的使用PowerShell备份数据库
  14. 【BZOJ3110】【ZJOI2013】k大数查询
  15. java~springboot~ibatis数组in查询的实现
  16. python中使用for循环,while循环,一条命令打印99乘法表
  17. [Spark][Python]DataFrame select 操作例子II
  18. php 分页实现 和 php 大文件上传失败的处理方式
  19. 基于 Web 的 Go 语言 IDE - Wide 1.5.2 发布!
  20. Ubuntu+Nginx+uWSGI+Flask应用

热门文章

  1. Centos7 ssh免密码登陆
  2. 16个ASP.NET MVC扩展点【附源码】
  3. js生成验证码并验证的登录页面
  4. 海康录像机 POE 输送距离 实验
  5. SpringBoot常用注解的介绍及使用 - 转载
  6. [Python] Understand Mutable vs. Immutable objects in Python
  7. ExtAspNet依据Grid导出Excel
  8. Linq查询案例
  9. amaze ui和bootstrap有哪些差别?
  10. 6.Maven之(六)setting.xml配置文件详解