题目描述
代码
package shulun;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class 哥德巴赫猜想 {
/**
* @param args
* @throws IOException
* @throws NumberFormatException
*/
public static int cnt=0;
public static final int N=(int) (1e6+10);
public static int prime[]=new int [N];
public static boolean st[]=new boolean[N];
public static void init (int n) {
for(int i=2;i<=n;i++){
if(!st[i]) prime[cnt++]=i;
for(int j=0;prime[j]<=n/i;j++){
st[i*prime[j]]=true;
if(i%prime[j]==0) break;
}
}
}
public static void main(String[] args) throws NumberFormatException, IOException {
// TODO Auto-generated method stub
BufferedReader bufferedReader =new BufferedReader(new InputStreamReader(System.in));
init(N-1);
while(true){
int n=Integer.parseInt(bufferedReader.readLine());
if(n==0) break;
for(int i=1;i<n;i++){
int b=n-prime[i];
if(!st[b]){
System.out.println(n+" = "+prime[i]+" + "+(n-prime[i]));
break;
}
}
}
}
}