//chebyshev's  theorem


#include <stdio.h>

#define maxprime  123456*2
 
 
int prime[maxprime + 1];
 
void make_prime(void)  //?´???°????±?????????¢??° 
{
    int i;
    int j;
    int n;
    int c;
     
    for (i = 2; i * i <= maxprime; i++){
        if (prime[i] == 0){
            for (j = i * 2; j <= maxprime; 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;
}