#include<stdio.h>
#include<math.h>
int main(){
  int box[300000]={},i,j,n,cnt;
  for(i=2;i<=123456*2;i++)
    box[i]=1;
  for(i=2;i<=sqrt(123456*2);i++){
    if(box[i]==1){
      for(j=i*i;j<=123456*2;j+=i)
        box[j]=0;
    }
  }
  while(1){
    cnt=0;
    scanf("%d",&n);
    if(n==0)
      break;
    for(i=n+1;i<=2*n;i++)
      cnt+=box[i];
    printf("%d\n",cnt);
  }
}

