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<iostream>
using namespace std;
int n;
bool isP(int x){
  if(x==0||x==1)return false;
  for(int i=2;i*i<=x;i++){
    if(x%i==0)return false;
  }
  return true;
}
int main(){
  while(cin>>n&&n){
    for(int i=n;i-2>=1;i--){
      if(isP(i)&&isP(i-2)){
	cout<<i-2<<' '<<i<<endl;
	break;
      }
    }
  }
}

C++: #include <iostream>
#include<vector>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
const int N = 10010;

bool isprime[N];
vector<int> prime;

//vectorありver
int makePrime1(bool type){
    REP(i, N) isprime[i] = true;
    isprime[0] = false;
    isprime[1] = false;

    for(int i = 2; i < N; i++){
        if(!isprime[i]) continue;
        prime.push_back(i);
        for(int j = i + i; j < N; j += i) isprime[j] = false;
    }
}

//なしver
int makePrime2(){
    REP(i, N) isprime[i] = true;
    isprime[0] = false;
    isprime[1] = false;

    for(int i = 2; (i * i) <= N; i++){
        if(!isprime[i]) continue;
        for(int j = i + i; j < N; j += i) isprime[j] = false;
    }
}

void dispVector(){
    REP(i, prime.size()){
        cout <<prime[i] <<endl;
    }
}

void dispDx(){
    REP(i, N){
        if(isprime[i]) cout <<i <<endl;
    }
}

int main(){
    makePrime2();

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

C++: #include "stdio.h"
const int MAX_V = 10000; // 1????????§????´???°??¨?????????
int prime[MAX_V+1]; // 1????´???°,0????´???°??§?????????
int main() {
    int i, k, n;
    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?????\???????????°????´???°??§?????????
            }
        }
    }
    while(scanf("%d", &n) != EOF) {
        //        int isprime = prime[v];
        //        if(isprime) printf("%d is a prime number\n", v);
        //        else printf("%d is not a prime number\n", v);
        int p1 = 3;
        int q1 = 5;
        for(i = n;0 <= i;i--){
            if(prime[i] == 1 && prime[i-2] == 1){  //??????????´???°
                if (q1 <= i) {
                    q1 = i;
                    p1 = i-2;
                }
            }
        }
        printf("%d %d\n",p1,q1);
        return 0;
    }
}
//????¨??????¨????????????????????????

C++: #include<stdio.h>

int main(){
  const int MAX_V = 100000;
  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 <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() && prime_table.back() <= sn; ++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();
            }
        }
        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;
int n;
bool isPrime(int x) {
  for(int i=2; i*i<=n; i++) {
    if(x % i == 0) return 0;
  }
  return 1;
}

int main() {
  while(cin >> n && n) {
    int mx = 5;
    for(int i=2; i<=n-2 ; i++) {
      if((isPrime(i)&isPrime(i+2)) == 1) {
	mx = i;
      }
    }
    cout << mx << ' ' << mx+2 << endl;
  }
  
  return 0;
}

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

int main()
{
	int n;

	while (cin >> n, n){
		vector<bool> num(n + 1, true);
		
		for (int i = 2; i <= n; i++){
			if (num[i]){
				for (int j = i; j * i <= n; j++){
					num[j * i] = false;
				}
			}
		}
		bool check = false;
		for (int i = n; i >= 5; i--){
			if (num[i]){
				for (int j = i - 1; j >= 5; j--){
					if (num[j]){
						if (i - j == 2){
							cout << j << " " << i << endl;
							check = true;
							break;
						}
					}
				}
			}
			if (check){
				break;
			}
		}
		num.clear();
	}
	
	return (0);
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    bool prime[10001];
    memset(prime,0,sizeof(prime));
    for(int i=2;i<sqrt(10001);i++){
        if(!prime[i])for(int j=i*2;j<10005;j+=i)prime[j]=1;
    }
    int num[210],co=0;
    for(int i=3;i<10001;i++){
        if(!prime[i]&&!prime[i+2]){
            num[co]=i;
            co++;
        }
    }
    int n;
    while(cin>>n,n){
        if(num[co-1]<n)cout<<num[co-1]<<" "<<num[co-1]+2<<endl;
        else{
            for(int i=co-1;i>-1;i--){
                if(num[i]+2<n){
                    cout<<num[i]<<" "<<num[i]+2<<endl;
                    break;
                }
            }
        }
    }
}

C++: #include <iostream>
#include <stdio.h>
using namespace std;
 
 int main() {
  int pr[10001],i,j,n;
  for (i=0;i<10001;i++) pr[i]=1;
  for (i=2;i<5000;i++) if (pr[i]==1) for (j=i+i;j<10001;j+=i) pr[j]=0;
  while(cin >> n) {
	  if (n==0) break;
	  for (;n>4;n--) if (pr[n]==1 && pr[n-2]==1) { cout << n-2 << ' ' << n << endl; break; }
  }
  return 0;
 }