#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#define INPUT_BUF_SIZE 1024
#define MAX_PRIME_NUM 500000

int main(void){
	int input;                    //??\???
	int prime[MAX_PRIME_NUM]={};  //prime[i]??????i????´???°??????0,????????°1
	int i,j;                      //???????????¨?????°
	int ans;                      //??????
	
	//0,1????´???°??§?????????????????????
	prime[0]=1;
	prime[1]=1;
	//2?????????????´???°??????????????????
	for(i=2;i<=MAX_PRIME_NUM;i++){
		//i????´???°?????????
		if(prime[i]==0){
			j=2;
			//i????????°?????¨????´???°??§?????????????????????(i???j???????´???°??????????????????)
			while(i*j<=MAX_PRIME_NUM){
				prime[i*j]=1;
				j++;
			}
		}
	}
	while(scanf("%d",&input)!=EOF){
	    if(input==0){
	        break;
	    }
		ans=0;
		//?´???°????????°?????°????????????
		for(i=input+1;i<=input*2;i++){
			if(prime[i]==0){
				ans+=1;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}