/*
* POJ_2909.cpp
*
* Created on: 2013年11月20日
* Author: Administrator
*/
#include <iostream>
#include <cstdio>
using namespace std;
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
/**
* 2 2 3 17
2 2 3 29
2 2 5 37
*/
using namespace std;
int su[10000002];
bool u[10000002];
int num = 0;
int n;
void prepare(){
int i,j;
memset(u,true,sizeof(u));
for(i = 2 ; i <= 10000002 ;++i){
if(u[i]){
su[++num] = i;
}
for(j = 1 ; j <= num ; ++j ){
if(i*su[j] >10000002){
break;
}
u[i*su[j]] = false;
if(i % su[j] ==0){
break;
}
}
}
}
int main(){
prepare();
int n;
while(scanf("%d",&n)!=EOF,n){
int ans = 0;
int i;
for(i = 2 ; i <= n/2 ; ++i){//注意,这里从2开始
if(u[i] && u[n-i]){
ans++;
}
}
printf("%d\n",ans);
}
return 0;
}