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

#define MAX (123456 * 2 + 1)

char prime[MAX];

int main(void)
{
    int i, j;

    memset(prime, 1, sizeof(prime));
    prime[0] = prime[1] = 0;
    for (i = 4; i < MAX; i += 2)
        prime[i] = 0;
    for (i = 3; i * i < MAX; i += 2)
        if (prime[i])
            for (j = i * 2; j < MAX; j += i)
                prime[j] = 0;

    for (;;) {
        int n, c = 0;

        scanf("%d", &n);
        if (n == 0)
            break;

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

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


    return 0;
}