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 <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <vector>

constexpr bool divisible(const std::size_t n, const std::size_t m)
{
    return (0 == n % m);
}

std::vector<std::size_t> prime_table = {2};

bool prime(const std::size_t n)
{
    const std::size_t found_last_prime = prime_table.back();
    if(found_last_prime < n)
    {
        std::list<std::size_t> undefined_table;

        for(std::size_t i = found_last_prime + 1; i <= n; ++i)
        {
            undefined_table.push_back(i);
        }

        const std::size_t sn = std::sqrt(n);
        for(std::size_t p = 0; !undefined_table.empty() && p < prime_table.size(); ++p)
        {
            for(auto u = undefined_table.begin(); u != undefined_table.end();)
            {
                if(divisible(*u, prime_table.at(p)))
                {
                    u = undefined_table.erase(u);
                }
                else
                {
                    ++u;
                }
            }
            if(!undefined_table.empty() && found_last_prime <= prime_table.at(p))
            {
                prime_table.push_back(undefined_table.front());
                undefined_table.pop_front();
                if(sn < prime_table.back())
                {
                    break;
                }
            }
        }
        prime_table.insert(prime_table.end(), undefined_table.begin(), undefined_table.end());
    }
    return std::binary_search(prime_table.begin(), prime_table.end(), n);
}

std::pair<std::size_t, std::size_t> find_twin_prime(const std::size_t limit, const bool next_skip = false)
{
    return prime(limit) ?
        prime(limit - 2) ?
        std::make_pair(limit - 2, limit) :
        find_twin_prime(limit - (next_skip ? 3 : 1), true) :
        find_twin_prime(limit - (next_skip ? 2 : 1), false);
}

int main()
{
    std::size_t n;

    while(std::cin >> n, n != 0)
    {
        const auto&& t = find_twin_prime(n);
        std::cout << t.first << " " << t.second << std::endl;
    }
}

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

using namespace std;

const int MAXN = 10100;
bool sieve[MAXN] = {true, true};

int main(){
  for (int i = 2; i * i < MAXN; i++){
    if (sieve[i]) continue;
.   for (int j = i * i; j < MAXN; j += i) sieve[j] = true;
. }
. int N;
. while (cin >> N, N){
    while (sieve[N] or sieve[N - 2]) N--;
.   cout << N - 2 << " " << N << endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int isPrime(int n){
    for(int i=2;i<n;i++){
        if(n%i==0)return 0;
    }
    return 1;
}
int main(void){
    int n=1;
    while(n){
        cin>>n;
        for(int i=n;i>0;i--){
            if(isPrime(i)*isPrime(i-2)){
                cout<<i-2<<" "<<i<<endl;
                break;
            }
        }
    }
    return 0;
}

C++: #include <stdio.h>

const int MAX_V = 1000000;
int prime[MAX_V+1];
int main() {
  int i, k, n, j, 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;
      }
    }
  }
  for( ;; ) {
    scanf( "%d", &n );
    if( n == 0 )break;
    for( j = 2; j <= n; j++ ) {
      int isprime = prime[j];
      int isprimee = prime[j-2];
      if( isprime == 1 && isprimee == 1 ) {
        q1 = j;
        p1 = q1 - 2;
      }
    }
    printf( "%d %d\n", p1, q1 );
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n, m[10001];
bool p(int x){
  if(m[x]>=0) return m[x];
  for(int i=2;i*i<=n;i++) {
    if(x%i==0) return m[x]=0;
  }
  return m[x]=1;
}
main() {
  memset(m,-1,sizeof(m));
  while(cin>>n&&n) {
    int mx=5;
    for(int i=2;i<=n-2;i++)if((p(i)&p(i+2)))mx=i;
    printf("%d %d\n",mx,mx+2);
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

vector<int> get_prime(int n){
    if(n <= 1) return vector<int>();
    vector<bool> is_prime(n+1, true);
    vector<int> prime;
    is_prime[0] = is_prime[1] = 0;
    for (int i = 2; i <= n; ++i) {
        if(is_prime[i]) prime.emplace_back(i);
        for (auto &&j : prime){
            if(i*j > n) break;
            is_prime[i*j] = false;
            if(i % j == 0) break;
        }
    }
    return prime;
}

int main() {
    auto v = get_prime(10000);
    vector<int> ans;
    for (int i = 0; i+1 < v.size(); ++i) {
        if(v[i+1] - v[i] == 2){
            ans.emplace_back(v[i]+2);
        }
    }
    int n;
    while(cin >> n, n){
        auto x = *--upper_bound(ans.begin(),ans.end(), n);
        printf("%d %d\n", x-2, x);
    }
    return 0;
}

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

const int lim = 10000;
bool prime[lim+10];

int main(){
    int n;
    memset(prime,-1,sizeof(prime));
    for(int i = 3; i <= lim; i += 2)
        if(prime[i])
            for(int j = i*2 ; j <= lim; j += i)
                prime[j] = 0;

    while(cin >> n && n){
        if(n % 2 == 0) n--;
        for(int i = n; i >= 5; i -= 2){
            if(prime[i] && prime[i-2]){
                cout << i-2 << " " << i << endl;
                break;
            }
        }
    }
    return 0;
}

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

string prime(int n){
  int i,j;
  string p = "001";
  while(p.size()<=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(){
  int n;
  string p;
  while(1){
    cin >> n;
    if(!n)break;

    p = prime(n);

    while(n){
      if(p[n]=='1' && p[n-2]=='1'){
	cout << n-2 << " " << n << endl;
	break;
      }
      n--;
    }
  }
}

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

using namespace std;

bool PrimeData[10001] = { false,false,true,true };

void findPrimeNumber() {
	int limit;
	bool flag;

	for (int num = 5; num < 10001; num += 2) {
		limit = sqrt(num) + 1;
		flag = true;
		for (int j = 2; j < limit; j++) {
			if (num%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag) {
			PrimeData[num] = true;
		}
	}
}

int main() {
	int n;

	findPrimeNumber();

	while (cin >> n, n) {
		while (n > 4) {
			if (PrimeData[n] && PrimeData[n - 2]) {
				cout << n - 2 << " " << n << endl;
				break;
			}
			n--;
		}
	}

	return 0;
}

C++: #include<stdio.h>
const int MAX_X = 10000;
int prime[10000];

int main(){

	int i, k, n;

	int border[10];
	for( i = 2; i <= MAX_X; i++) {
		prime[i] = 1;
	}

	for(i = 2; i*i <= MAX_X; i++){
		if(prime[i]) {
			for(k = 2 * i; k <= MAX_X; k += i){
				prime[k] = 0;
			}
		}
	}

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