/* 
   AOJ 1172
   Chebyshev's Theoreme
   2015.4.28
 */

#include<stdio.h>
#define MAX_N 123456

int count_prime(int n)
{
  int n_limit = n * 2, i, j, prime_by_n = 0, prime_by_nlimit = 0, prime_num[MAX_N * 2 + 1];
  
  for(i = 0; i < MAX_N * 2 + 1; i++)
    {
      prime_num[i] = 1;
    }

  prime_num[0] = 0;
  prime_num[1] = 0;  

  for(i = 2; i <= n_limit; i++)
    {
      /* printf("%d\n", i*i); */
      /* fflush(stdout); */

      if(prime_num[i] == 1)
	{
	  for(j = 2; i * j <= n_limit; j++)
	    {
      /* printf(" %d\n", j); */
      /* fflush(stdout); */
	      prime_num[i * j] = 0;
	    }
	}
    }


  for(i = 0; i <= n_limit; i++)
    {
      if(prime_num[i] == 1)
	{
	  if(i <= n)
	    {
	      prime_by_n++;
	      prime_by_nlimit++;
	    }
	  else
	    {
	      prime_by_nlimit++;
	    }
	}
    }

  return prime_by_nlimit - prime_by_n;
  
}

int main(void)
{
  int n, prime_num;
  while(1)
    {

      scanf("%d", &n);

      if(n == 0)
	{
	  break;
	}
      
      prime_num = count_prime(n);
      printf("%d\n", prime_num);

    }
  return 0;
}