#include <stdio.h>
#define MAX_2N (2 * 123456)

int isPrime[MAX_2N + 1];

void sieve()
{
  int p, q;
  for (p = 2; p <= MAX_2N; p++) isPrime[p] = 1;
  for (p = 2; p <= MAX_2N; p++) {
    if (isPrime[p]) {
      for (q = p + p; q <= MAX_2N; q += p) {
        isPrime[q] = 0;
      }
    }
  }
}

int chebyshev(int n)
{
  int cnt = 0, p;
  for (p = n + 1; p <= n + n; p++) {
    if (isPrime[p]) cnt++;
  }
  return cnt;
}

int main()
{
  int n;
  sieve();
  for (;;) {
    scanf("%d", &n);
    if (n == 0) break;
    printf("%d\n", chebyshev(n));
  }
  return 0;
}