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)
        {
            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(prime_table.front() <= sn)
                {
                    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++: 1

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 = 0; max=0;
		REP(i, 5, n) {
			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 <cmath>
#include <cstring>
#include <iostream>
#include <ostream>
#include <vector>
 
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> v) {
  os << "[";
  for(int i = 0; i < int(v.size()); i++) {
    os << v[i] << (i == int(v.size()) - 1 ? "" : ", ");
  }
  os << "]";
  return os;
}
 
// n 以下の素数のリストを返す O(nlog(log(n)))
std::vector<int> eratosthenes(int n) {
  std::vector<int> is_prime(n + 1, 1);
  std::vector<int> primes;

  is_prime[0] = is_prime[1] = 0;
  primes.push_back(2);
  for(int i = 3; i <= n; i += 2) {
    if(is_prime[i]) {
      primes.push_back(i);
      for(int j = 3; i * j <= n; j += 2) {
        is_prime[i * j] = 0;
      }
    }
  }

  return primes;
}
 
int main() {
  int n;
  std::vector<int> primes = eratosthenes(10000);
 
  while(cin >> n, n) {
    int a = 2, b = 3;
    for(int i = 1; i < primes.size(); i++) {
      if (primes[i] > n) break;

      if(primes[i] - primes[i - 1] == 2) {
        a = primes[i - 1];
        b = primes[i];
      }
    }
    cout << a << " " << b << endl;
  }
 
  return 0;
}

C++: #include <iostream>

using namespace std;

bool P[10001];

void eratos()
{
	for( int i = 0;i < 10001;i++ ) P[i] = true;
	P[0] = P[1] = false;
	for( int i = 2;i * i < 10001;i++ ){
		if( P[i] ) for( int j = 2;i * j < 10001;j++ ) P[i * j] = false;
	}
}

int main(int argc, char const* argv[])
{
	int n;

	eratos();
	while( cin >> n && n != 0 ){
		for( int i = n;i >= 0;i-- ){
			if( P[i] && P[i - 2] ){
				cout << i - 2 << " " << i << endl;
				break;
			}
		}
	}

	return 0;
}

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

using namespace std;

#define MAX 10100
 
bool prime[MAX];

void make()
{
    fill(prime, prime + MAX, 1);
    prime[0] = prime[1] = 0;
     
    for (int i = 2; i*i < MAX; i++) {
        if (prime[i]) {
            for (int j = i*2; j < MAX; j += i) {
                prime[j] = 0;
	    }
	}
    }
}
 
int main()
{
    int n;
     
    make();
    while (cin >> n, n) {
        int a, b;
        for (int i = 0 ; i <= n; i++) {
            if (i >= 2 && prime[i] && prime[i-2]) {
                a = i-2;
                b = i;
            }
        }
        cout << a << ' ' << b << endl;
    }
    return 0;
}

C++: #include<stdio.h>
const int MAX_V = 10000;
int prime[MAX_V];
int main(){
	int i, k, n =10, cnt = 0;
	int border[10];
	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;
			}
		}
	}
	int difference[MAX_V+1];
	int idx = 2;
	for( i = 2; i < MAX_V; i++){
		if(prime[i] == 1){
			difference[i] = i - idx;
			idx = i;
		}
	}
	
	for( i = 0; i < n; i++){
		scanf("%d", &border[i]);
		if(border[i] == 0) break;
		cnt++;
	}
	
	int max[10] = {0};
	for( i = 0; i < cnt; i++){
		for( k = 2; k <= border[i]; k++){
			if( difference[k] == 2 && k > max[i]){
				max[i] = k;
			}
		}
		printf("%d %d\n", max[i] - 2, max[i]);
	}
	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,p1,q1,i1 = 0,i2 = 0,max = 0,k;
  while(1){
    scanf("%d",&n);
    if(n == 0){
      break;
    }
    for(k = 0;k + 2 < n;k++){
      i1 = isprime(k);
      if(i1 == 1){
      i2 = isprime(k + 2);
      }
      if(i1 == 1 && i2 == 1){
        max = k;
      }
    }
    p1 = max;
    q1 = max + 2;
    printf("%d %d\n",p1,q1);
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
bool is_p[1000000];

void erast(int n, vector<int> &p){
  is_p[0] = is_p[1] = 1;
  p.push_back(1);
  for (int i = 2; i <= n; i++) {
    if(is_p[i] == 1)continue;
    is_p[i] = 1;
    p.push_back(i);
    for (int j = 2*i; j <= n; j += i) {
      is_p[j] = 1;
    }
  }
}
  
int main(int argc, char *argv[]){
  int n;
  while(cin >> n, n){
    memset(is_p, 0, sizeof(is_p));
    vector<int> p;
    erast(n, p);
    for (int i = p.size() - 1; i > 0; i--) {
      if(p[i] - p[i - 1] == 2){
        std::cout << p[i - 1] << " " << p[i] << std::endl;
        break;
      }
    }
  }
  return 0;
}