poj 2909

水题一道。

//============================================================================
// Name        : 2909.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

bool flag[100000];
int tag[100000];
int n, num;


int main() {
	freopen("a.txt", "r", stdin);
	for(int i = 2;i <= 32768/2;i++){
		if(flag[i] == false){
			for(int j = 2*i;j <= 32768;j+=i){
				flag[j] = true;
			}
		}
	}
	flag[1] = true;
	while(scanf("%d", &n)&&n){
		num = 0;
		memset(tag, 0, sizeof(tag));
		for(int i = 1;i <= n;i++){
			if(tag[i] == 0&&tag[n-i] == 0){
				if(flag[i] == false&&flag[n-i] == false){
					num++;
					tag[i] = 1;
					tag[n-i] = 1;
				}
			}
		}
		printf("%d\n", num);
	}
	return 0;
}

  

posted @ 2011-07-24 20:51  KOKO's  阅读(99)  评论(0编辑  收藏  举报