HDACM 1397
因为输入的值小于2^15,所以可以采用打表的方式来做。简单暴力
import java.util.Scanner;public class Main{public static void main(String[] args) {boolean noPrime[] = new boolean[32768];for (int i = 2; i < noPrime.length; i++) {if (!noPrime[i]) {for (int j = i*2; j < noPrime.length; j+=i) {noPrime[j]=true;}}}Scanner sc = new Scanner(System.in);while (sc.hasNext()) {int n = sc.nextInt();if (n==0) {break;}int count = 0;for (int i = 2; i <= n/2; i++) {if (!noPrime[i]&&!noPrime[n-i]) {count++;}}System.out.println(count);}sc.close();}
}