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

//???????????°x??????p<=???x?????????????´???????p??????????????¨????????§???????????¨???????´???°???????????????
int isPrime(int x){
    int i;
    double rx = sqrt(x); //???x
    if(x<2) return 0; //2???????°?????????????????´???°??§?????????
    else if(x==2) return 1; //2????´???°
    else if(x%2==0) return 0; //??¶??°????´???°??§?????????
    for(i=3;i<=rx;i+=2) //?\???°????????????????????????????????¨???????´???°??????
        if(x%i==0) return 0;
    return 1;
}

int main(void){
    int i,n,c;
    for(;;){
        scanf("%d", &n);
        if(n==0) break;
        c=0; //?????????
        for(i=n+1;i<=2*n;i++)
            if(isPrime(i)) c++;
        printf("%d\n", c);
    }
    return 0;
}