#include <stdio.h>

#define MAX_PRIME	(123456 * 2)


int prime[MAX_PRIME + 1];

void make_prime(void)
{
    int i;
    int j;
    int n;
    int c;
    
    for (i = 2; i * i <= MAX_PRIME; i++){
        if (prime[i] == 0){
            for (j = i * 2; j <= MAX_PRIME; j += i){
				prime[j] = 1;
            }
        }
    }
}
	


int main(void)
{
	int n;
    int i;
	int count;
	
	make_prime();

    while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		
		count = 0;
		for (i = n + 1; i <= n * 2; i++){
			if (prime[i] == 0){
				count++;
			}
		}
		printf("%d\n", count);
    }
    
    return (0);
}