Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
	)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	prime := make([]int, 1000001)
	prime[0], prime[1] = -1, -1
	for i := 2; i < 1000001; i++ {
		if prime[i] != -1 {
			prime[i] = 1 // i means "prime"
			for j := i+i; j < 1000001; j += i {
				prime[j] = -1 // -1 means "not prime"
			}
		}
	}
	for scanner.Scan() {
		ret := 0
		a, _ := strconv.Atoi(scanner.Text())
		if a == 0 {
			break
		}
		for i := 1; i <= a/2; i++ {
			if prime[i] == 1 && prime[a-i] == 1 {
				ret++
			}
		}
		fmt.Println(ret)
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

vector<string> ans;
string str;


bool comp(string a, string b)
{
  for(int i = 0; i < a.size(); i++){
    if(a[i] < b[i]) return true;
  }
  return false;
}

void solve(int idx, string s)
{
  if(idx == s.size()){
    if(s != str) ans.push_back(s);
    return;
  }
  if(s[idx] < 'z' && s.find(s[idx]) == idx){
    if(s[idx] == 'a'){
      solve(idx + 1, s);
      s[idx]++;
      solve(idx + 1, s);
    } else {
      s[idx]++;
      solve(idx + 1, s);
    }
  } else {
    solve(idx + 1, s);
  }
  if(s[idx] < 'z' && s[idx] == str[idx]){
    if(s[idx] == 'a'){
      solve(idx + 1, s);
      s[idx]++;
      solve(idx + 1, s);
    } else {
      s[idx]++;
      solve(idx + 1, s);
    }
  }
  return;
}

int main()
{
  while(cin >> str, str != "#"){
    solve(0, str);
    sort(ans.begin(), ans.end());
    cout << ans.size() << endl;
    if(ans.size() <= 5){
      for(int i = 0; i < ans.size(); i++){
	cout << ans[i] << endl;
      }
    } else {
      for(int i = 0; i < ans.size(); i++){
	if(i < 5 || ans.size()-5 <= i) cout << ans[i] << endl;
      }
    }
    ans.clear();
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
#define MAX 1000100
 
int prime[MAX-4];
 
void is_prime(){
    for(int i = 0 ; i < MAX ; i++) prime[i] = 0;
    prime[0] = prime[1] = 1;
    for(int i = 4 ; i < MAX ; i += 2) prime[i] = 1;
     
    for(int i = 3 ; i*i < MAX ; i++){
        if(prime[i]) continue;
        for(int j = i*2 ; j < MAX ; j+= i)
            prime[j] = 1;
    }
}
 
    int main(){
        int n;
         
        is_prime();
         
        while(true){
            cin >> n;
            if(!n) break;
             
            int cnt = 0;
            for(int i = 2 ; i <= n/2 ; i++){
                if(!prime[i]&&!prime[n-i]) cnt++;
            }
            cout << cnt << endl;
        }
         
        return 0;
    }

C++: #include<iostream>
#define size 1000001
using namespace std;
int p[size];
int n,a,b,cnt;
void prime();
int main(){
  prime();
  while(1){
    cin>>n;
    if(n==0)break;
    cnt=0;
    for(int i=2;i<=n/2;i++){
      if(p[i]==1&&p[n-i]==1){
	//	cout<<i<<' '<<n-i<<endl;
	cnt++;
      }
    }
    cout<<cnt<<endl;
  }
  return 0;
}

void prime(){
  for(int i=0;i<size;i++)p[i]=1;
  p[0]=p[1]=0;
  for(int i=4;i<size;i+=2)p[i]=0;
  for(int i=3;i*i<=size;i+=2){
    if(p[i]==0)continue;
    for(int j=i*2;j<size;j+=i)p[j]=0;
  }
}

C++: #include <iostream>
using namespace std;
#define MAX_N 1000001
int main(){
  int n;
  int isPrime[MAX_N];
  fill(isPrime,isPrime + MAX_N,1);

  isPrime[0] = isPrime[1] = 0;

  for(int i = 2 ; i*i < MAX_N ; i++){
    if(isPrime[i]){
      for(int j = i*2 ; j < MAX_N ; j+=i )isPrime[j] = 0;
    }
  }

  int p = 0;
  int ans[MAX_N] = {0};

  for(int i = 0 ; i < MAX_N ; i++)if(isPrime[i])isPrime[p++] = i;

  for(int i = 0 ; i < p ; i++ ){
    for(int j = i ; isPrime[i] + isPrime[j] < MAX_N ; j++ ){
      ++ans[isPrime[i] + isPrime[j]];
    }
  }

  while( cin >> n,n ){
    cout << ans[n] << endl;
    }
  return 0;
}

C++: #include <cstdio>

#define MAX 1000000

bool prime[MAX];

void make(){
  fill(prime,prime+MAX,true);
  prime[0] = prime[1] = false;

  for(int i = 2 ; i*i < MAX ; i++){
    if(prime[i]){
      for(int j = 2*i ; j < MAX ; j += i){
	prime[j] = false;
      }
    }
  }
}

int main(){
  make();
  int n;
  while(scanf("%d" ,&n),n){
    int cnt = 0;
    for(int i = 2 ; i+i <= n ; i++){
      if(prime[i] && prime[n-i]){
	cnt++;
      }
    } 
    printf("%d\n" ,cnt);
  }

  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for((i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

const int MAX_N = 1000002;
int n, primes[100000], prime_sz = -1;
bool used[100000];
bool sieve[MAX_N];


int solve() {
  int ans = 0;
  fill(used, used + 100000, false);

  for (int i = 0; i < prime_sz; ++i) {
    if (used[i]) continue;
    const int value = n - primes[i];
    const int vl = lower_bound(primes, primes + prime_sz, value) - primes;
    if (used[vl]) continue;
    if (n != primes[i] + primes[vl]) continue;
    used[i] = used[vl] = true;
    ans++;
  }
  return ans;
}

int main() {
  // prime
  primes[0] = 2;
  int cnt = 1;
  fill(sieve, sieve + MAX_N, true);
  sieve[0] = sieve[1] = false;
  for (int i = 4; i < MAX_N; i+=2) sieve[i] = false;
  for (int i = 3; i < MAX_N; i+=2) if (sieve[i]) {
    primes[cnt] = i; cnt++;
    for (int j = i + i; j < MAX_N; j+=i) sieve[j] = false;
  }
  prime_sz = cnt;
  
  while (cin >> n, n) {
    cout << solve() << endl;
  }
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

//エラトステネスの篩
const int Num = 1000009;
vector<bool> p(Num, true);
void Eratosthenes() {
	p[0] = false;
	p[1] = false;
	for (int i = 0; i < Num; ++i)if (p[i])
		for (int j = i * 2; j < Num; j += i)p[j] = false;
}

int main() {
	Eratosthenes();
	int n;
	while (cin >> n && n) {
		int ans = 0;
		for (int i = 3; i < n / 2; i += 2) {
			if (p[i] && p[n - i]) {
				//cout << i << ", " << n - i << endl;
				ans++;
			}
		}
		ans += (p[n / 2]);
		Cout(ans);
	}
}

C++: #include <bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<n;i++)
using namespace std;
int a[1000000]={1,1},s[500000],c;
int main(){
	r(i,2,100000)
	for(int j=i*2;j<1000000;j+=i)a[j]++;
	r(i,2,1000000)if(!a[i])s[c++]=i;
int n;
while(cin>>n,n){
	int ss=0;
	r(i,0,n){
		if(s[i]>n)break;
	r(j,i,n){
		if(s[j]>n)break;
	if(s[i]+s[j]==n){ss++;}
	cout<<ss<<endl;
}
}
}
}

C++: #include<iostream>
#include<cmath>
using namespace std;
const int MAX_SIZE = 1000000;
bool p[MAX_SIZE+1];
int p_num[MAX_SIZE+1];
int p_count=0;

void prime_set(int MAX){
	p[0] = p[1] = false;
	for(int i=2; i<=MAX; i++) p[i] = true;
	int LIMIT = (int)sqrt(MAX);
	for(int i=2; i<=LIMIT; i++){
		if(p[i]){
			for(int j=2*i; j<=MAX; j++){
				if(j%i==0)
					p[j]=false;
			}
		}
	}
	
	for(int i=2; i<=MAX; i++){
		if(p[i]){
			p_num[p_count] = i;
			p_count++;
		}
	}
	
}

void slove(int n){
	int p,q,count=0;
	int k=0;
	while(p<(n/2)){
			p=p_num[k];
			for(int j=0; j<p_count; j++){
				q=p_num[j];
				if(p+q == n){
				 count++;
				}
			}
		k++;
	}
	cout << count << endl;
}

int main(){
	int n;
	while(cin >> n){
		if(n==0) break;
		prime_set(n);
		slove(n);
	}
	return 0;
}