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