#include <stdio.h>
#define MAX 123456*2

int main(void){
  int n, i, j;
  int count=0;
  int p_num[MAX];

  p_num[0]=p_num[1]=0;
  for(i=2;i<MAX;i++)
    p_num[i]=1;

  while(1){
    count=0;
    scanf("%d", &n);

    if(n==0 || 123456<n)
      break;

    for(i=n+1;i<=2*n;i++){
      for(j=2; j*j<=i;j++){
	if(i%j==0)
	  p_num[i]=0;
      }
      if(p_num[i]==1)
	count+=p_num[i];
    }
    
    printf("%d\n", count);
  }

  return 0;
}