#include <stdio.h>

#define MAX (40000)

int prime[MAX + 1];

int main(void)
{
	int i, j, num;
	int n;
	
	prime[0] = prime[1] = 0;
	
	for (i = 2; i <= MAX; i++){
		prime[i] = 1;
	}
	
	for (i = 2; i * i <= MAX; i++){
		for (j = i * i; j <= MAX; j += i){
			prime[j] = 0;
		}
	}
	
	while (scanf("%d", &n), n){
		i = 0;
		j = n;
		num = 0;
		
		while (i <= j){
			if (prime[i] && prime[j] && i + j == n){
//				printf("%d %d %d %d\n", i, prime[i], j, prime[j]);
				num++;
			}
			i++;
			j--;
		}
		
		printf("%d\n", num);
	}
	
	return (0);
}