#include<iostream>
using namespace std;

#define sz size()

string MakeTable(int n){
  int i,j;
  string p = "001";
  while(p.sz<=n)p += "10";
  i = 3;
  while(i*i<n){
    for(j=3*i;j<n;j+=2*i)p[j]='0';
    do{i+=2;}while(p[i]-'1');
  }
  return p;
}

int main(){
  string p;
  int n,ans;

  while(1){
    cin >> n;
    if(!n)break;

    p = MakeTable(n);

    if(p[n-2]=='1')ans = 1;
    else ans = 0;

    for(int i=3;i<=n/2;i+=2){
      if(p[i]=='1' && p[n-i]=='1')ans++;
    }

    cout << ans << endl;
  }
}