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>
#include <vector>

using namespace std;

vector<int> furui(10001, 0);

int main () {
	furui[0] = furui[1] = 1;
	for (int i = 2; i*i <= 10001; i++) {
		if (furui[i] == 0) {
			for (int j = 2; j <= 10000/i; j++) {
				furui[i*j] = 1;
			}
		}
	}
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		for (int i = n; i > 0; i--) {
			if (furui[i] == 0 && furui[i-2] == 0) {
				cout << i-2 << " " << i << endl;
				break;
			}
		}
	}
	return 0;
}

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

struct twinPrime {
    int p;
    int q;
};

twinPrime make_twinPrime(int x, int y) {
    twinPrime myTwinPrime = {x, y};
    return myTwinPrime;
}

int main() {
    const int numPrimes = 10005;
    bool primes[numPrimes];
    for (int i = 2; i != numPrimes; ++i) {
        primes[i] = true;
    }

    for (int i = 2; i != int(sqrt(numPrimes)); ++i) {
        if (primes[i]) {        
            for (int j = 2; i * j < numPrimes; ++j) {
                primes[i*j] = false;
            }
        }
    }

    int previous = 2;
    vector<twinPrime> allTwinPrimes;

    for (int i = 2; i != numPrimes; ++i) {
        if (primes[i]) {
            if (i - previous == 2) {
                allTwinPrimes.push_back(make_twinPrime(previous, i));
            }
            previous = i;
        }
    }

    int n;
    while (cin >> n && n != 0) {
        int maxP = 0, maxQ = 0;
        for (int i = 0; i != allTwinPrimes.size(); ++i) {
            if (allTwinPrimes[i].q > n) {
                maxP = allTwinPrimes[i-1].p;
                maxQ = allTwinPrimes[i-1].q;
                break;
            }
        }
        cout << maxP << " " << maxQ << endl;
    }
    return 0;
}

C++: #include <stdio.h>

const int MAX_V = 1000000; // 100万まて?の素数表を作る
int prime[MAX_V+1]; // 1か?素数,0か?素数て?ない

int main() {
    int i, k, n;
    int ans[2] ={};
    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; // 素数の2倍以上の倍数は素数ではない
            }
        }
    }
    
    while(1) {
        scanf("%d", &n);
        if(n == 0) break;
        for(int i = n; i >= 5; i--) {
            if(prime[i] == 1) {
                ans[1] = i;
                if(prime[i - 2] == 1) {
                    ans[0] = i - 2;
                    break;
                }
            }
        }
        printf("%d %d\n", ans[0], ans[1]);
    }
    
    return 0;
}

C++: #include <stdio.h>
const int MAX_V = 1000000; // 100???????????????????f???????¢\????°???¬?????
int prime[MAX_V+1];
int main() {
	int k,i,max,min,n; // 1????????f???????C0????????f????????????????????¢
	for(i = 2; i <= MAX_V; i++) {
		prime[i] = 1; // 2???????£????f????????????°??????¨
	}
	for(i = 2; i*i <= MAX_V; i++) {
		if(prime[i]) {
			for(k = 2 * i; k <= MAX_V; k += i) {
				prime[k] = 0; // ???f??????2???{???????£????{?????????f????????????????????¢
			}
		}
	}
	while(scanf("%d",&n)){
		if(n == 0)break;
		max = 0; min = 0;
		for(i = n;i > 0;i--){
			if(prime[i] && prime[i-2]){
				max = i;
				min = max -2;
				//printf("%d %d\n",i-2,i);
				break;
			}
		}
		printf("%d %d\n",min,max);
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<queue>
#include<utility>
#include<algorithm>
#include<cctype>
using namespace std;

int so[10010];
int set[10010];

int main(){
	int x=0;
	while(1){
	cin>>set[x];
			if(set[x]==0)break;
		x++;
	}
	
	for(int y=0;y<x;y++){
	
	
	int num[10000];
	for(int i=0;i<set[y];i++){
	num[i]=1;
	}
	
	
	for(int i=2;i<set[y];i++){
		if(num[i]==1){
			for(int j=0;i*(j+2)<set[y];j++){
			num[i*(j+2)]=0;
			}
		}
	}
	for(int i=2;i<set[y];i++){
		if(num[i]){
		so[i]=i;
		}
	}
	
	sort(so, so+set[y],greater<int>() );

	for(int i=0;i<set[y];i++){
		if(so[i]-so[i+1]==2){
		cout<<so[i+1]<<" "<<so[i]<<endl;
			break;
		}
	}
	
	}


}

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;

	while (cin >> N)
	{
		for (int i = (N - 1); i > 1; i--)
		{
			if (prime_check(i) == true && prime_check(i - 2) == true)
			{
				cout << i - 2 << ' ' << i << endl; goto Exit;
			}
		}

	Exit:;
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 10;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    vector<int> prime(MAX_N, 1);
    prime[0] = prime[1] = 0;
    for(int i = 2; i * i < MAX_N; i++)
    {
        for(int j = 2 * i; j < MAX_N; j += i) prime[j] = 0;
    }
    while(cin >> n, n)
    {
        for(int i = n; i >= 0; i--)
        {
            if(prime[i] and prime[i - 2])
            {
                cout << i - 2 << " " << i << endl;
                break;
            }
        }
    }
    return 0;
}

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

#define NUM 10000
bool prime[NUM+1];

void sieve()
{
  prime[0]=prime[1]=false;
  for(int i=2;i<=NUM;i++)
    prime[i]=true;
  for(int i=2;i<=NUM;i++)
    if(prime[i])
      for(int j=i*2;j<=NUM;j+=i)
	prime[j]=false;
}

int main()
{
  int n;

  sieve();
  for(;;){
    cin>>n;
    if(!n) break;
    for(int i=n;i>=5;i--)
      if(prime[i]&&prime[i-2]){
	cout<<i-2<<" "<<i<<endl; break;
      }
  }
}

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

C++: #include<iostream>
#include<algorithm>
#include<numeric>
#include<iterator>
#include<vector>

using namespace std;
typedef unsigned int val;

struct pred{
	bool operator()(int m, int n) { return m - n == 2; }
};

int main() {
	int n;
	while(cin>>n && n)
	{
		vector<int>so;
		bool flag[10010];
		flag[0]=flag[1]=false;
		for(int i=2; i<=n; i++)
		{
			if( flag[i] )
			{
				so.push_back(i);
				for(int j=i*2; j<n; j+=i) flag[j]=false;
			}
		}
		vector<int>::reverse_iterator ite = adjacent_find(so.rbegin(), so.rend(), pred());
		cout<< *(ite+1) << " "<< *ite << endl;

	}
	return 0;
}