任意一个偶数(大于2)都可以由2个素数组成,组成偶数的2个素数有很多种情况,本题目要求输出组成指定偶数的两个素数差值最小的素数对。
public class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
String str;
while((str=bf.readLine())!=null) {
int count=Integer.valueOf(str);
int left=count/2;
int right=count/2;
while (left > 0 && right < count){
// if(left != right){
if (isNum(left) && isNum(right)) {
System.out.println(left );
System.out.println(right);
break;
}
left--;
right++;
}
}
}
private static boolean isNum(int n) {
for (int i = 2; i *i<=n ; i++) {
if (n%i==0) {
return false;
}
}
return false;
}
}
本文探讨了哥德巴赫猜想的应用,即任意一个大于2的偶数都可以表示为两个素数之和。通过一个Java程序,我们寻找构成指定偶数的两个素数,且这两个素数的差值最小。该程序读取输入的偶数值,然后计算并输出满足条件的素数对。

被折叠的 条评论
为什么被折叠?



