#include <stdio.h>
int main(void)
{
  int n,i,j,c,f;
  while(scanf("%d",&n),n){
    c=0;
    for(i=n+1;i<=2*n;i++){
      f=1;
      for(j=2;j*j<=i;j++){
	if(!(i&j)){
	  f=0;
	  break;
	}
      }
      if(f) c++;
    }
    prinf("%d\n",c);
  }
  return 0;
}