#include <stdio.h>
int main(){

  int n,a,result,i,j;

  while(1){

    scanf("%d",&n);
    if(n == 0) break;

    result=0;
    if(n == 1){

      printf("1\n");
      continue;

    }

    for(i = n+1; i <= 2*n; i++){

      a=0;
      for(j = 2; j*j <= i; j++){

        if(i%j == 0){

	  a=1;
          break;

        }

      }

      if(a == 0) result++;

    }

    printf("%d\n",result);

  }

  return 0;

}