#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define N 1000000
int main() {
	int i, j, cnt, *p, n;
	p = (int*)calloc(N, sizeof(int));
	for (i = 2; i <= (int)sqrt((double)N); ++i) if (!*(p + i)) for (j = 2; j*i < N; j++) *(p + i*j) = 1;
	while (1) {
		scanf("%d", &n);
		if (n == 0) break;
		cnt = 0;
		for (i = 2; i <= n / 2; i++) if (!*(p + i) && !*(p + n - i)) cnt++;
		printf("%d\n", cnt);
	}
	free(p);
	return 0;
}