歌德巴赫猜想的证明
Problem Description
验证“每个不小于6的偶数都是两个素数之和”,输入一个不小于6的偶数n,找出两个素数,使它们的和为n。
Input
输入一个不小于6的偶数n。
Output
找出两个素数,使它们的和为n。只需要输出其中第一个素数最小的一组数据即可。
Example Input
80
Example Output
80=7+73
01 |
import java.util.Scanner; |
02 |
03 |
04 |
public class Main
{ |
05 |
static int f( int a){ |
06 |
boolean flag= true ; |
07 |
int flag1
= 0 ; |
08 |
if (a
< 2 )
{ |
09 |
return flag1; |
10 |
} else { |
11 |
12 |
for ( int i
= 2 ;
i <= a/ 2 ;
i++) { |
13 |
14 |
if (a
% i == 0 )
{ |
15 |
16 |
flag
= false ; |
17 |
break ; |
18 |
} |
19 |
} |
20 |
if (!flag){ |
21 |
return flag1
= 0 ; |
22 |
} else { |
23 |
return flag1
= 1 ; |
24 |
} |
25 |
} |
26 |
} |
27 |
public static void main(String
args[]){ |
28 |
Scanner
input = new Scanner(System.in); |
29 |
int n
= input.nextInt(); |
30 |
for ( int i
= 2 ;i<n;i++){ |
31 |
if (f(i)== 1 ){ |
32 |
if (f(n-i)== 1 ){ |
33 |
System.out.println(n+ "=" +i+ "+" +(n-i)); |
34 |
break ; |
35 |
} |
36 |
} |
37 |
} |
38 |
} |
39 |
|
40 |
} |
41 |
42 |