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;
using ll = long long;
using P = pair<int, int>;

const int MAX_N = 10101;

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

int sieve(int n) {
    int p = 0;
    for (int i = 0; i <= n; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            prime[p++] = i;
            for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;
        }
    }
    return p;
}

int main() {
    sieve(MAX_N);
    sort(prime, prime + MAX_N);
    int n;
    while (cin >> n && n) {
        int p = 0, q = 0;
        int idx = upper_bound(prime, prime + MAX_N, n) - prime;
        idx--;
        for (int i = idx; i > 0; i--) {
            if (prime[i] - 2 == prime[i - 1]) {
                p = prime[i - 1];
                q = prime[i];
                break;
            }
        }
        cout << p << ' ' << q << endl;
    }
}

C++: #include "stdio.h"
//#include "time.h"
//?????§??????????´???°?????????????????????
// 5<= n <= 10000
//p1=?°????????´???°p2=??§???????´???°

int isprime(int n) {
    for(int i = 2; i < n; i++) {   //??????????§????????????¨??§??¶??°??§??????????´???°??¨??????
        if(n % i == 0)return 0;    //????????????????????§?´???°??§?????????
    }
    return 1;
}


int main(){
    int i,n,p1,q1;
    //    clock_t start, now;//??£?¨?
    while(1){
        scanf("%d",&n);
        //        start = clock(); // ????§???????
        if(n == 0)break;
        for(i = n;3 <= i;i--){
            if (isprime(i) == 1 && isprime(i - 2) == 1) break;
        }
        p1 = i-2;
        q1 = i;
        //        now = clock(); // ????????????
        //        printf("%f\n", (double)(now - start) / CLOCKS_PER_SEC);//??¬???
        printf("%d %d\n",p1,q1);
    }
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

vector<int> prime;
bool is_prime[1000010];
int min_factor[1000010];
int sieve(int n) {
  fill(is_prime + 2, is_prime + 1000010, true);
  min_factor[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime.emplace_back(i);
      for (int j = 2 * i; j <= n; j += i) {
        is_prime[j] = false;
        if (min_factor[j] == 0) min_factor[j] = i;
      }
    }
  }
  return prime.size();
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  sieve(10010);
  int n;
  while (cin >> n, n) {
    int p = -1, q = -1;
    for (int i = 0; i + 1 < int(prime.size()); i++) {
      if (prime[i + 1] > n) break;
      if (prime[i + 1] - prime[i] != 2) continue;
      p = max(p, prime[i]);
      q = max(q, prime[i + 1]);
    }
    cout << p << " " << q << endl;
  }

  return 0;
}

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

#define N_MAX 10001

bitset<N_MAX> primes;

void make_cache() {
    primes.set();
    for (int i = 2; i < N_MAX; i++) {
        if (primes[i]) {
            for (int j = i + i; j < N_MAX; j+=i) {
                primes.reset(j);
            }
        }
    }
}

void solve(int n) {
    for (int i = n; 4 <= i; i--) {
        if (primes[i] && primes[i-2]) {
            cout << i-2 << ' ' << i << endl;
            break;
        }
    }
}

int main() {
    make_cache();
    int n;
    while (cin >> n) {
        if (n == 0) break;
        solve(n);
    }
    return 0;
}

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

bool is_prime[10001];

int main() {
  int n,p1,q1;
  for(int i=0;i<10001;i++) {
    is_prime[i] = true;
  }

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

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

  while(cin >> n) {

    if(n==0) break;

    for(int i=0;i<10001;i++) {
      if(is_prime[n-i]) {
        q1 = n-i;
        if(is_prime[n-i-2]) {
          p1 = n-i-2;
          break;
        }
      }
    }
    printf("%d %d\n",p1,q1);
  }
}

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

#define MAX_N 1000000

int prime[MAX_N], twin[MAX_N];

void isprime(int c) {
	prime[2] = 1;
	for (int i = 3; i < c; i += 2) {
		for (int j = 3; j < sqrt(i); j += 2) {
			if (i%j == 0) { 
				goto E; 
			}
		}
		prime[i] = 1;
	E:;
	}
}

void istwin(int d) {
	for (int i = 5; i < d; i++) {
		if (prime[i - 2] + prime[i] == 2) {
			twin[i] = i;
		}
		else {
			twin[i] = twin[i - 1];
		}
	}
}

int n;

int main() {
	isprime(MAX_N);
	istwin(MAX_N);
	while (true) {
		cin >> n;
		if (n == 0) {
			break;
		}
		cout << twin[n] << endl;
	}
}

C++: #include<iostream>
#include<string>
using namespace std;
int prime[10000];
int main(){
	int count=0;
	int k=2;
	while(true){
		bool t=true;
		for(int i=0;i<count;i++){
			if(k%prime[i]==0)
				t=false;
		}
		if(t==true){
			prime[count]=k;
			count++;
		}
		k++;
		if(k==10000)
			break;
	}
	int n;
	while(true){
	cin>>n;
	if(n==0)
		break;
	k=n;
	while(true){
		bool up=false;
		for(int i=0;i<count;i++){
			if(prime[i]==k)
				up=true;
		}
		bool down=false;
		for(int i=0;i<count;i++){
			if(prime[i]==k-2)
				down=true;
		}
		if(up==true&&down==true)
			break;
		k--;
	}
	cout<<k-2<<" "<<k<<endl;
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
    int a,i,flg1,p,q,l,b,a2,b2,n[10000],m[10000],k=0;
	scanf("%d",&a);
	while(a!=0){
	    flg1=1;
		p=0;
		q=0;
		a2=0;
		b2=0;
	    for(i=2;i<=a;i++){
		    for(l=2;l<i-2;l++){
			    b=i%l;
				if(b==0) {
				    flg1=0;
					break;
				}
			}
			if(flg1==1) {
				if(p==0){
				    q=i;
				}
				else if(p!=0){
				    q=i;
				}
				if(q-2==p){
				    a2=p;
					b2=q;
				}
				else{
				    p=q;
				}
			}
			flg1=1;
			if(a==5||a==6) a2=3,b2=5;
		}
		n[k]=a2,m[k]=b2;
		k++;
		scanf("%d",&a);
	}
	for(i=0;i<k;i++) printf("%d %d\n",n[i],m[i]);
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
  vector<int>prime;
  prime.push_back(2);
  for(int i=3;i<10000;i+=2){
    int flag=1;
    for(int j=2;j<=sqrt(i);j++){
      if(i%j==0){
	flag=0;
	break;
      }
    }
    if(flag)
      prime.push_back(i);
  }
  int n;
  while(cin>>n,n){
    for(int i=prime.size();i>0;i--){
      if(prime[i]<=n&&(prime[i]-prime[i-1])==2){
	cout<<prime[i-1]<<" "<<prime[i]<<endl;
	break;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int prime[10010];
bool is_prime[10010];

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

int main(){
	sieve(10000);
	while(1){
		int n;
		cin>>n;
		if(n==0) break;
		for(int i=n;i>=5;i--){
			if(is_prime[i] && is_prime[i-2]){
				o(i-2<<" "<<i);
				break;
			}
		}
	}
}