#include<stdio.h>
int main(void){
  int sosu[250000];
  int i,j,k;
  int ans[256];
  sosu[2] = 1;
  for(i=3;i<250000;i+=2){
    sosu[i] = 1;
  }
  for(i=3;i*i<250000;i+=2){
    if(sosu[i] == 1){
      for(j=i*i;j<250000;j+=i*2){
	sosu[j] = 0;
      }
    }
  }
  for(k=0;k>=0;k++){
    int n;
    int count = 0;
    scanf("%d",&n);
    if(n == 0)break;
    for(i=n+1;i<=n*2;i++){
      if(sosu[i] == 1){
	count++;
      }
    }
    ans[k] = count;
  }
  for(i=0;i<k;i++){
    printf("%d\n",ans[i]);
  }
  return 0;
}