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

int main (){

	int count=0;
	int point[10000]={};
	int input = 0;
	int max=0;

	int result[1000]={};
	int prime[1000000]= {};
	int sq_num=0;
	int deli=0;
	int i=0;
	while(1){
		scanf("%d",&input);
		if(input == 0 ){
			break;
		}
		count = 0;
	  prime[2]=1;
	  i=3;
	  while(1){
		prime[i]=1;
		i++;
		prime[i]=0;
		i++;
		if( i > 1000000){
		  break;
		}
	  }
	  i=input;
	  sq_num = (int)sqrt(2*i);
	  i=2;	
	  while(1){
		if(prime[i]==1){
		  deli=i;
		  while( input*2 > deli ){
			deli += i;
			prime[deli] = 0;
		  }
		}
		i++;
		if(sq_num < i){
		  break;
		}
	  }
	  i=input;
	  i++;
	  while(1){
		if(prime[i] == 1){
		  result[count]++;
		}
		i++;
		if (2*input < i){
		  break;
		}
	  }
	  if(input == 0 ){
		break;
	  }
	  printf("%d\n",result[count]);
	  count++;
	}
	
	return 0;
}