解题思路: 无
注意事项: 注意存在差为0,1的特殊值时,
输入:
5 2
2 2 2 2 2
输出 :
NO
0
输入:
5 2
2 2 2 3 3
输出:
NO
1
参考代码:
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String []args) { Scanner in =new Scanner(System.in); int n=in.nextInt(),k=in.nextInt(); int arr[]= new int[n]; for(int i=0;i<n;i++) arr[i]=in.nextInt(); Arrays.sort(arr); int tmp=arr[n-k]-arr[k-1]; boolean flag=true; if(tmp<2) flag=false; //注意处理特殊情况 for(int i=2;i<=Math.sqrt(tmp);i++) { //判断素数 if(tmp%i==0) { flag=false; break; } } if(flag) System.out.println("YES"); else System.out.println("NO"); System.out.println(tmp); in.close(); } }
0.0分
2 人评分
C语言考试练习题_排列 (C语言代码)浏览:1316 |
【出圈】 (C语言代码)浏览:553 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:540 |
A+B for Input-Output Practice (V) (C++代码)浏览:450 |
这可能是一个假的冒泡法浏览:985 |
字符串对比 (C语言代码)浏览:1401 |
WU-C语言程序设计教程(第三版)课后习题12.1 (C++代码)浏览:925 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:467 |
A+B for Input-Output Practice (VI) (C语言代码)浏览:552 |
【亲和数】 (C语言代码)浏览:597 |