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<bits/stdc++.h>
using namespace std;

#define MAX_N 12000

int prime[MAX_N];
bool is_prime[MAX_N + 1];


void prime_generate(){
	int p = 0;
	for(int i = 0; i <= MAX_N; i++) is_prime[i] = true;

	is_prime[0] = is_prime[1] = false;

	for(int i = 2; i <= MAX_N; i++){
		if(is_prime[i]){
			prime[p++] = i;
			for(int j = 2 * i; j <= MAX_N; j += i) is_prime[j] = false;
		}
	}
}

void solve(int n){
	int p1 = -1, p2 = -1;

	for(int i = 0; prime[i+1] <= n; i++){
		if(prime[i+1] - prime[i] == 2){
			if(p1 <= prime[i]){
				p1 = prime[i];
			}
			if(p2 <= prime[i+1]){
				p2 = prime[i+1];
			}
		}
	}
	cout << p1 << " " << p2 << endl;
}

int main(){
	prime_generate();

	int n;
	while(cin >> n){
		solve(n);
	}
}

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

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

bool isPrime[10010];

void Prime()
{
    rep(i, 10010) isPrime[i] = true;

    isPrime[0] = false;
    isPrime[1] = false;

    for(int i = 2; i <= sqrt(10010); i ++)
    {
        if(isPrime[i])
        {
            for(int j = i * 2; j <= 10010; j += i)
                isPrime[j] = false;
        }
    }
}

int main()
{
    Prime();

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

    return 0;
}

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

int main(){
  const int MAX_V = 10000;
  int prime[MAX_V+1];
  int i, k, v, ans, dif;
  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(scanf("%d", &v) != EOF){
    if(v == 0) break;
    for(k = v; k >= 2; k--){
      ans = prime[k];
      if(ans == 0){
        dif = prime[k - 2];
        if(dif == 0){
          printf("%d %d\n", k - 2, k);
          break;
        }
      }
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

vector<int> sieve_of_eratosthenes(int n) {
  vector<int> primes(n);
  for (int i = 2; i < n; ++i)
    primes[i] = i;
  for (int i = 2; i*i < n; ++i)
    if (primes[i])
      for (int j = i*i; j < n; j+=i)
        primes[j] = 0;
  return primes;
}

int main() {
  int a;
  while (cin >> a, a) {
    vector<int> p = sieve_of_eratosthenes(a + 1);
    for (int i = a; i > 2; --i) {
      if (p[i - 2] && p[i]) {
        cout << i - 2 << ' ' << i << endl;
        break;
      }
    }
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
bool isp[10000];
main()
{
    isp[0]=isp[1]=1;
    for(int i=2;i<=100;i++)
    {
        if(isp[i])continue;
        for(int j=i*i;j<=10000;j+=i)isp[j]=1;
    }
    int n;
    while(cin>>n,n)
    {
        while(!isp[n]&&!isp[n-2])n--;
        cout<<n-2<<" "<<n<<endl;
    }
}

C++: #include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

inline bool isPrime(int a){
  if(a<=1)return false;
  for(int i=2;i*i<=a;i++){
    if(a % i == 0)return false;
  }
  return true;
}

int main(){
  vector<int> table(10001,0);
  for(int i=1;i<=10000;i++){
    if(i>=2 && isPrime(i) && isPrime(i-2)){
      table[i] = i;
    }else{
      table[i] = table[i-1];
    }
  }

  int n;
  while(cin >> n){
    if(n==0)break;
    cout << table[n]-2 << " " << table[n] << endl;
  }  
}

C++: #include<iostream>
#include<cmath>
using namespace std;
bool p(int n) {
	for (int i = 2; i <= sqrt(n); i++)if (n%i == 0)return false; return true;
}
int main(){
	int n;
	while (cin >> n){
		if (n == 0)return 0;
		for (int i = n;; i--){
			if (p(i) && p(i - 2)) {
				cout << i - 2 << ' ' << i << endl;
				goto end;
			}
		}
	end:;
	}
}

C++: #include <stdio.h>
const int MAX_V = 10000; // 1????????§????´???°??¨?????????

int main() {
	int i, k, n, p, q;
	int prime[MAX_V+1]; // 1????´???°???0????´???°??§?????????
	for(i = 2; i <= MAX_V; i++) {
		prime[i] = 1; // 2??\???????´???°??¨??????
	}
	for(i = 2; i*i <= MAX_V; i++) {
		if(prime[i]) {
			for(k = 2 * i; k <= MAX_V; k += i) {
				prime[k] = 0; // ?´???°???2?????\???????????°????´???°??§?????????
			}
		}
	}
	//?´???°??¨fin
	//while(scanf("%d",&n) != 0){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(i=n;i>=3;i--){//???????????¨????´???°????????????
			if(prime[i] == 1 && prime[i-2] == 1){
				p = i;
				q = p-2;
				break;
			}
		}
	// 	ans[a]=i; a++;
	// 	ans[a]=i-2; a++;
	// }
	// for(i=0;i<=a;i=i+2){
	// 	printf("%d %d\n",ans[i],ans[i+1]);
	// }
		printf("%d %d\n",p,q);
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,i;
	while(1){
	scanf("%d",&n);
	if(n==0) break;
		for(i=n;i>0;i--){
			if(i==5||i==7){
				printf("%d %d\n",i-2,i);
				break;
			}
			else if(i%2!=0&&i%3!=0&&i%5!=0&&i%7!=0){
				if((i-2)%2!=0&&(i-2)%3!=0&&(i-2)%5!=0&&(i-2)%7!=0){
					printf("%d %d\n",i-2,i);
					break;
				}
			}
		}
	}
	return 0;
}