#include <stdio.h>

int number[300000];

void func1(int array[], int size, int num) {
	int i;
	
	for(i = 0; i < size; i++)
		array[i] = num;
}

int main() {
	int n;
	int i, j;
	int temp;

	func1(number, 300000, 1);
	
	number[0] = 0; number[1] = 0;

	for(i = 2; i < 300000; i++) {
		if(number[i])
			for(j = 2; i * j < 300000; j++)
				number[i * j] = 0;
	}

	while(1) {
		scanf("%d", &n);
		if(!n) break;

		temp = 0;

		for(i = n + 1; i <= 2 * n; i++)
			if(number[i]) temp++;

		printf("%d\n", temp);
	}

	return 0;
}