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

  return 0;
}
 