#include <stdio.h>
#include <string.h>
#include <math.h>

char prime[500000];

void make_prime(int n)
{
	int i, j;

	for (i = 2; i < sqrt(n); i++){
		for (j = i + i; j < n; j += i){
			prime[j] = 0;
		}
	}
}

int main(void)
{
	int n;

	memset(prime, 1, sizeof(prime));
	prime[0] = prime[1] = 0;
	make_prime(500000);
	
	while (scanf("%d", &n), n){
		int i, j;
		int c = 0;

		for (i = n + 1; i <= 2 * n; i++){
			c += prime[i];
		}

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

	return (0);
}