#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
#include<math.h>
//#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
#define N 123456
int main() {
	int i, j, cnt = 0, p[N*2] = {},n;
	for (i = 2; i <= (int)sqrt(N*2); ++i) if (!p[i]) for (j = 2; j*i < N*2; j++) p[i*j] = 1;
	while (~fscanf(stdin, "%d", &n), n) {
		cnt = 0;
		for (i = n + 1; i <= 2 * n; i++) if (!p[i]) cnt++;
		P(d, cnt);
	}
	return 0;
}