从偶数除以2开始往两边,当两个数是素数时就满足。这个挺妙
查找组成一个偶数最接近的两个素数
https://www.nowcoder.com/practice/f8538f9ae3f1484fb137789dec6eedb9
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int ou = in.nextInt();
// 从中间开始往两侧,差值从小到大
int n = ou / 2;
int m = ou / 2;
while (noSusu(n) || noSusu(m)) {
n--;
m++;
}
System.out.println(n);
System.out.println(m);
}
private static boolean noSusu(int m) {
// 一个数除了能被1和它本身整除,就是素数也叫质数
// 注意是从2到它的平方根(包含它的平方根),但凡有一个可以整除就不是素数
for (int i = 2; i <= (int) Math.sqrt(m); i++) {
if(m % i == 0){
return true;
}
}
return false;
}
}


查看26道真题和解析