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(found_last_prime <= prime_table.at(p))
            {
                prime_table.push_back(undefined_table.front());
                undefined_table.pop_front();
                if(sn < prime_table.front())
                {
                    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<iostream>
#include<string>
using namespace std;
int main(){
	const int MAX = 10000;
	int katarogu[MAX] = { 0 };
	const int NOsosu = 1;
	int num[MAX] = { 0 };
	num[1] = NOsosu;
	for (int i = 3; i < MAX; i = i + 2){
		for (int j = 3; j*j <= i; j = j + 2){
			if (i%j == 0){ num[i] = NOsosu; break; }
		}
		if (num[i] != NOsosu && num[i - 2] != NOsosu){ katarogu[i] = 1; }
	}
	int a;
	while (cin >> a,a!=0){
		for (; a > 6; a--){
			if (katarogu[a] != 0){
				cout << a-2<<" "<<a << endl;
				break; 
			}
		}


	}

	return 0;
}

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

const int MAX_S = 101000;

bool p[MAX_S];

void prime() {
  fill(p, p+MAX_S, true);
  p[0] = false;
  p[1] = false;
  for(int i = 2; i < MAX_S; i++) {
    if(p[i]) {
      for(int j = 2; i*j < MAX_S; j++) {
	p[i*j] = false;
      }
    }
  }
}

int main() {
  int n;
  prime();
  while(cin >> n, n) {
    int ans;
    for(int i = 5; i <= n; i++) {
      if(p[i] && p[i-2]) ans = i;
    }
    cout << ans-2 << ' ' << ans << endl;
  }
}

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

using namespace std;

bool isPrime[10001];

void setPrime( bool *p, int size )
{
	memset(p, true, size);
	p[0] = p[1] = false;

	for(int i=2; i < size; ++i) {
		if(!p[i]) continue;
		for(int j=i+i; j < size; j+=i) {
			p[j] = false;
		}
	}
}

int main( void )
{
	setPrime(isPrime, 10001);
	int n;
	while(cin >> n, n) {
		bool hit = true;
		for(int i=n-2; i > 0 && hit; --i) {
			if(isPrime[i]) {
				if(isPrime[i+2]) {
					cout << i << ' ' << i+2 << endl;
					hit = false;
				}
			}
		}
	}
	return 0;
}

C++: #include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;
const int MAX = 10000;
/** Problem0150 : Twin Prime **/
int main()
{
	int n;
	bool prime[MAX];
	int before=0, ans1=0, ans2, max;
	
	for (int i=0; i<MAX; i++)
		prime[i] = true;
	
	prime[0] = false; prime[1] = false;
	
	for (int i=2; i<MAX; i++) {
		if (prime[i]) {
			for (int j=2; i*j<MAX; j++) {
				prime[i*j] = false;
			}
		}
	}
	
	while (cin>>n, n!=0) {
		before = 1; max=0;
		REP(i, 3, n+1) {
			if (prime[i]) {
				if (i-before==2) {
					if (i>max) {
						max = i;
						ans1 = before;
						ans2 = i;
					}
				}
				before = i;
			}
		}
		cout << ans1 << " " << ans2 << endl;
	}
	return 0;
}

C++: #include <stdio.h>

int isprime(int n){
    for(int i = 2; i * i <= n; i++) {
        if(n % i == 0) return 0;  //素数でない
    }
    return 1; //素数である
}

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

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

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;






int main() {
	vi v(10010, 1);
	v[0] = 0;
	v[1] = 1;
	for (int i = 2; i < 10010; i++) {
		if (v[i] == 1) {
			for (int j = 2; j <= 10010 / i; j++) {
				v[i*j] = 0;
			}
		}
	}
	int n;
	while (cin >> n&&n > 0) {
		int ans;
		for (int i = n; i > 0; i--) {
			if (v[i] && v[i - 2]) {
				ans = i;
				break;
			}
		}
		cout << ans - 2 << " " << ans << endl;
	}
}

C++: #include<iostream>
#include<fstream>
#include<vector>
#define N 10000

int gcd(int q1,int p1){
    if(q1%p1==0) return p1;
    return gcd(p1,q1%p1);
}

int sosu(int j){
    if(j<2)return 0;
    if(j==2)return 1;
    if(j%2==0)return 0;
    for(int i=3; i<=j/2; i++){
        if(j%i==0)return 0;
    }
    return 1;
}

int main(){
    std::vector<int> n;
    n.resize(N);
    for(int i=0; i<N; i++){
        std::cin >> n[i];
        if(n[i]==0)break;
    }
    for(int i=0; i<N; i++){
        if(n[i]==0)break;
        for(int j=n[i]; j>5; j--){
            if(sosu(j)&&sosu(j-2))
                if(gcd(j,j-2)==1){
                    std::cout << j-2 << " " << j <<std::endl;
                    break;
                }
            }
        }
    return 0;
}