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 <stdio.h>

int isprime(int n) {
	int i;
    for(int i = 2; i * i <= n; i++) {
        if(n % i == 0) return 0;
    }
    return 1; 
}

int main(){
	int k,suu,an1,an2;
    while(1){
        scanf("%d",&suu);
        if(suu != 0){
            for(k=2;k<=suu;k++){
                if(isprime(k-2)==1 && isprime(k)==1){
                    an1=k-2;
                    an2=k;
                }
            }
            printf("%d %d\n",an1,an2);
        }
        else{
    	    break;
        }
    }
}

C++: #include <cmath>
 #include <cstring>
 #include <iostream>
 #include <ostream>
 #include <vector>
   
 using std::cin;
 using std::cout;
 using std::cerr;
 using std::endl;
   
 // 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 <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
int primes[1230];
vector<int> twin_left, twin_right;

bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}

int main()  {

    int idx = 0, diff, id, n;
    for (int i = 2; i <= 10000; i++) if (isPrime(i)) primes[idx++] = i;
    for (int i = 1; i < idx; i++) {
        diff = primes[i] - 2;
        id = int(lower_bound(primes, primes+i, diff)-primes);
        if (id >= 0 && primes[id] == diff) twin_left.push_back(diff), twin_right.push_back(primes[i]);
    }
    for (; ;) {
        scanf("%d", &n);
        if (n == 0) break;
        idx = int(upper_bound(twin_right.begin(), twin_right.end(), n) - twin_right.begin())-1;
        printf("%d %d\n", twin_left[idx], twin_right[idx]);
    }

    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,i,prime[10000];
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(i=n;i>=5;i--){
			if(isprime[i]==1&&isprime[i-2]==1){
				printf("%d %d\n",i-2,i);
				break;
			}
		}
	}
	return 0;
}

C++: #include <stdio.h>

const int MAX_V = 10000;
int prime[MAX_V+1];

void init(){
    int i, k, v;
    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 isprime(int n){
    return prime[n];
}

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	#define MAX (int)1e5
	bool sosu[MAX];
	memset(sosu,true,MAX);
	for(int i=4;i<MAX;i+=2)sosu[i]=false;
	for(int i=3;i<MAX;i+=2)
	for(int j=3*i;j<MAX;j+=2*i)sosu[j]=false;
	int n;
	while(cin>>n,n){
		int i;
		for(i=n;i>=2;i--)if(sosu[i]&&sosu[i-2])break;
		cout<<i-2<<" "<<i<<endl;
	}
}

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

using namespace std;

bool prime_check(int N)
{
	if (N == 1) { return false; }

	for (int i = 2; i <= sqrt(N); i++)
	{
		if (N % i == 0)
		{
			return false;
		}
	}

	return true;
}

int main()
{
	int N[100], I[100], c = 0;

	while (cin >> N[c])
	{
        if(N[c] == 0){ goto END; }

		for (int i = (N[c] - 1); i > 1; i--)
		{
			if (prime_check(i) == true && prime_check(i - 2) == true)
			{
				I[c] = i; goto Exit;
			}
		}
	Exit:;

        c++;
	}

        END:;

        for(int i = 0; i < c; i++)
        {
            cout << I[i - 2] << ' ' << I[i] << endl;
        }

	return 0;
}