#include <stdio.h>

#define N 300000
int c[N];

int main(void)
{
    int n, i, j;
    for(i=2;i*i<N;++i) if (!c[i])
        for(j=i*i;j<N;j+=i) c[j]=1;

    while (scanf("%d", &n), n) {
        int res=0;
        for(i=n+1;i<=n+n;++i) res+=!c[i];
        printf("%d\n", res);
    }
    return 0;
}