#include <stdio.h>
#include <math.h>
int sosu(int n){
    int i=3,x,bl=1;
    double sn = sqrt(n);
    if (n == 2) {
        return bl;
    }
    if (n<2 || n%2==0) {
        bl=0;
        return bl;
    }
    while (i <= sn) {
        if (n%i == 0) {
            bl=0;
            return bl;
        }
        i+=2;
    }
    
    return bl;
}

int main(int argc, const char * argv[]) {
    
    int n,i,count=0;
    while (1) {
        scanf("%d",&n);
        if (n==0) {
            break;
        }
        
        for (i=n+1; i<=2*n; i++) {
            count+=sosu(i);
        }
        
        printf("%d\n",count);
        count=0;
        
    }
    return 0;
}