Go: package main

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

var scanner= bufio.NewScanner(os.Stdin)

func main() {
	MAX := 10001
	SQRT := 100
	isPrime := make([]bool, MAX)
	for i :=range isPrime {
		isPrime[i] = true
	}
	for i := 3; i < SQRT; i += 2 {
		if isPrime[i] {
			for j := i*i; j < MAX; j += i {
				isPrime[j] = false
			}
		}
	}
	// log.Println(isPrime)
	tbl := make([]int, MAX)
	ans := 0
	for i := 5; i < MAX; i += 2 {
		if isPrime[i] && isPrime[i-2] {
			ans = i
		}
		tbl[i] = ans
	}
	// log.Println(tbl)
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		if n&1 == 0 {
			n--
		}
		fmt.Printf("%d %d\n", tbl[n]-2, tbl[n])
	}
}

C++: #include <iostream>
#include <stack>
#include <math.h>
#include <vector>

bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);

    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0){
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}


int main(){

    int n = 0, tmp = 1, max = 4, qi = 0, qimax = 0;
    std::vector<int> v, Qs;
    while(1){
        std::cin >> tmp;

        if(tmp > max){
            max = tmp;
        }

        if(tmp == 0){
            break;
        }

        v.resize(n+1);
        v[n] = tmp;
        n++;
    }

    for(int i = 3; i <= max; i++){

        if(IsPrime(i) && IsPrime(i+2)){
            Qs.resize(qi + 1);
            //std::cout << i + 2 << std::endl;
            Qs[qi] = (i + 2);
            qi++;
        }

    }
    qi--;
    qimax = qi;
    tmp = 0;
    
    while(tmp < n){

       if( v[tmp] < Qs[qi] ){

            //std::cout << "qi : " << qi << std::endl;    
            qi--;
            continue;

       }else{// v[tmp] >= Qs.top

            v[tmp] = Qs[qi];
            qi = qimax;
            tmp++;

       }

    }
    
    for (int i = 0; i < n; i++){
        std::cout << v[i] - 2 << " " << v[i] << std::endl; 
    }

    
    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;

bool p[10010];

int era(){
	fill(p, p+10010, true);
	p[0] = p[1] = false;

	for(int i=0; i < 10010; i++){
		if(!p[i]) continue;

		for(int j=i+i; j < 10010; j+=i){
			p[j] = false;
		}
	}
}

int main(){
	era();
	int input;

	while(cin >> input, input){
		for(int i= input; 0 < i; i--){
			if(p[i] && p[i-2]){
				cout << i-2 << " " << i << endl;
				break;
			}
		}
	}
}

C++: #include <iostream>
#include <algorithm>

using namespace std;

const int MAX_P = 10020;
bool prime[MAX_P];
int twin_prime[MAX_P];
int size;

void init()
{
    for (int i = 0; i < MAX_P; i++)
        prime[i] = true;
    prime[0] = prime[1] = false;

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

    for (int i = 0; i < MAX_P; i++) 
        if (prime[i] && prime[i + 2])
            twin_prime[size++] = i;
}


int main()
{
    init();

    int n;
    while (cin >> n, n) {
        n -= 2;
        for (int i = 0; i < MAX_P; i++)
            if (twin_prime[i] >= n) {
                cout << twin_prime[i - 1] << " " << twin_prime[i - 1] + 2 << endl;
                break;
            }
    }

    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<numeric>
#include<iterator>
#include<vector>

using namespace std;
typedef unsigned int val;

struct pred{
	bool operator()(int m, int n) { return m - n == 2; }
};

int main() {
	int n;
	while(cin>>n && n)
	{
		vector<int>so(10000);
		so.clear();
		bool flag[10010];
		flag[0]=flag[1]=false;
		for(int i=2; i<=n; i++)
		{
			if( flag[i] )
			{
				so.push_back(i);
				for(int j=i*2; j<=n; j+=i) flag[j]=false;
			}
		}
		vector<int>::reverse_iterator ite = adjacent_find(so.rbegin(), so.rend(), pred());
		cout<< *(ite+1) << " "<< *ite << endl;

	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cmath>

std::vector<bool> Eratosthenes(const int n){
    std::vector<bool> primes(n+1, true);
    primes[0] = primes[1] = false;

    for(int i=2; i<=std::sqrt(n); ++i){
        if(!primes[i])
            continue;
        for(int j=i*i; j<=n; j+=i)
            primes[j] = false;
    }
    return primes;
}

void MaximumTwinPrimes(const std::vector<bool> &primes){
    for(int i=primes.size()-1; i>=2; --i){
        if(primes[i] && primes[i-2]){
            std::cout << i-2 << " " << i << std::endl;
            return;
        }
    }
}

int main(){
    int n;
    while((std::cin >> n) && n > 0){
        std::vector<bool> primes = Eratosthenes(n);
        MaximumTwinPrimes(primes);
    }
}

C++: #include <stdio.h>
const int MAX_V = 100000;
int prime[MAX_V+1];
int main(){
  int i,k,v,n,j,i1 = 0,i2 = 0,max = 0,p1,q1;
  for(i = 2;i <= MAX_V;i++){
    prime[i] = 1;
  }
  for(i = 2;i*i <= MAX_V;i++){
    if(prime[i]){
      for(k = 2 * i;k <= MAX_V;k += i){
        prime[k] = 0;
      }
    }
  }
  while(1){
    scanf("%d",&n);
    if(n == 0){
      break;
    }
    for(j = 0;j + 2 < n;j++){
      int isprime = prime[j];
      int isprime2 = prime[j + 2];
      if(isprime) i1 = 1;else i1 = 0;
      if(isprime2) i2 = 1;else i2 = 0;
      if(i1 == 1 && i2 == 1){
        max = j;
      }
    }
    p1 = max;
    q1 = max + 2;
    printf("%d%d\n",p1,q1);
  }
  return 0;
}

C++: #include <stdio.h>
const int MAX_V = 10000; // 100???????????????????f???????¢\????°???¬?????
int prime[MAX_V+1];
int main() {
	int k,i,max,min,n; // 1????????f???????C0????????f????????????????????¢
	for(i = 2; i <= MAX_V; i++) {
		prime[i] = 1; // 2???????£????f????????????°??????¨
	}
	for(i = 2; i*i <= MAX_V; i++) {
		if(prime[i]) {
			for(k = 2 * i; k <= MAX_V; k += i) {
				prime[k] = 0; // ???f??????2???{???????£????{?????????f????????????????????¢
			}
		}
	}
	while(scanf("%d",&n)){
		if(n == 0)break;
		max = 0; min = 0;
		for(i = n;i > 0;i++){
			if(prime[i] && prime[i-2]){
				max = i;
				min = max -2;
				//printf("%d %d\n",i-2,i);
				break;
			}
		}
		printf("%d %d\n",min,max);
	}
	return 0;
}

C++: #include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

int prime[10001];

int main(){
	prime[0]=prime[1]=1;
	
	for(int i=2;i*i<10001;i++){
		if(prime[i]==1)continue;
		for(int j=2*i;j<10001;j+=i){
			prime[j]=1;
		}
	}
	
	int n;
	while(cin>>n){
		while(n>0){
			if(prime[n]==0 && prime[n-2]==0)break;
			else n--;
		}
		cout<<n-2<<" "<<n<<endl;
	}
}

C++: #include <iostream>
#include <cstdio>
using namespace std;

int main(){
	bool isprime[10001];
	for(int i=0; i<10001; ++i) isprime[i]=true;

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

	while(1){
		int n;
		scanf(" %d", &n);
		if(n==0) break;
		if(n%2 == 0) n--;
		
		for(int i=n; i>=5; --i){
			if(isprime[i] && isprime[i-2]){
				printf("%d %d\n", i-2, i);
				break;
			}
		}
	}

	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[10001],d,f,g,h,i,j;
	for(i=2;i<=10000;i++)	s[i]=1;
		s[1]=0;
	for(i=2;i<=10000;i++){
		if(s[i]==1){
			for(j=2;j<=5000;j++){
				if(i*j<=10000)
					s[i*j]=0;
			}
		}
	}
	while(1){
		d=0;
		f=0;
		scanf("%d",&a);
		if(a==0)	break;
		for(i=a;i>0;i--){
			if(s[i]==1){
				if(d==0) d=i;
				else f=i;
			}
			if(d!=0&&f!=0){
				if(d-f==2)
					break;
				d=f;
			}
		}
		printf("%d %d\n",f,d);
	}
	return 0;
}