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;

int main() {
    vector<bool> v(11111, true);
    v[0] = v[1] = false;
    for (int i = 2; i <= 10000 / 2; i++) {
        for (int j = 2; j * i <= 10000; j++) {
            v[i * j] = false;
        }
    }

    vector<pair<int,int> > d;
    for (int i = 0; i <= 10000 ; i++) {
        if (v[i] && v[i+2]) d.push_back(pair<int,int>(i, i+2));
    }

    int n;
    while (cin >> n, n) {
        auto iter = lower_bound(d.begin(), d.end(), pair<int,int>(n - 2,n - 2)) - 1;
        cout << iter->first << ' ' << iter->second << endl;
    }

    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, p1, q1, result, resultt;
  for( ;; ) {
    scanf( "%d", &n );
    if( n == 0 )break;
    for( i = 2; i <= n; i++ ) {
      result = isprime( i );
      resultt = isprime( i - 2 );
      if( result == 1 && resultt == 1 ) {
        q1 = i;
        p1 = q1 - 2;
      }
    }
    printf( "%d %d\n", p1, q1 );
  }
  return 0;
}

C++: #include <iostream>
#include <math.h>
using namespace std;
bool check(int x,int y){
        for(int i=2 ; i<=sqrt(x) ; i++ ){
                if(x%i==0)
                        return false;
                if(y%i==0)
                        return false;
        }
        return true;
}
int main(){
        int n;
        while(true){
                cin >> n;
                if(n==0)break;
                if(n<=6)
                        cout<<5<<" "<<3<<endl;
                int de=(n/6);
                for(int x=6*de ; x>0 ; x=de*6 ){
                        if(check(x+1,x-1)){
                                cout << x-1 <<" " << x+1 << endl;
                                break;
                        }
                        de--;
                }
        }
        return 0;
}

C++: #include <stdio.h>


#define MYSCAN scanf

int main(void){
	int n, p;
	int flag;
	int i, j;
	int tmp;

	while (1){
		MYSCAN("%d", &n);
		if (n == 0){ break; }

		p = 0;
		if (n % 2 == 0){ n--; }
		for (i = n; i > 1; i-=2){
			flag = 1;
			// iテ」ツ?古ァツエツ?ヲツ閉ーテ」ツ?凝」ツ?ゥテ」ツ??」ツ?凝」ツδ?」ツつァテ」ツδε」ツつッ
			for (j = i / 2; j > 1; j--){
				if (i % j == 0){
					flag = 0;
					break;
				}
			}

			// iテ」ツ?古ァツエツ?ヲツ閉ーテ」ツ??」ツ?」テ」ツ?淌」ツつ?
			if (flag == 1){
				// テ・ツ??」ツつ暗」ツつ?テ」ツ?、テ・ツケツエテ、ツクツ凝」ツ??」ツ?」テ」ツ?淌」ツつ嘉・ツ?コテ・ツ環?
				if (i == p - 2){
					printf("%d %d\n", i, p);
					break;
				}
				// テ」ツ?敕」ツ??」ツ?佚」ツつε」ツ?ェテ」ツ?凝」ツ?」テ」ツ?淌」ツつ嘉ィツ?ェテ・ツ按?」ツ?古・ツ??」ツ?ォテ」ツ?ェテ」ツつ?
				p = i;
			}

		}
	}
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

int main(void){
	vector<int> p;
	bool isPrime[10000];

	fill(isPrime, isPrime+10000, true);

	for(int i=2;i<10000;i++){
		if(isPrime[i]){
			p.push_back(i);
			for(int j=2;i*j<10000;j++){
				isPrime[i*j] = false;
			}
		}
	}
	int n;
	while(cin >> n && n){
		vector<int>::iterator upper = upper_bound(p.begin(),p.end(),n), lower;
		--upper;
		lower = upper;
		--lower;
		while(true){
			if(*upper - *lower == 2) break;
			--upper;
			--lower;
		}

		cout << *lower << " " << *upper << endl;

	}
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

vector<int> primes(int n) {
  vector<int> v(n);
  for (int i=2; i<n; i++) v[i] = i;
  for (int i=2; i*i<n; i++)
    if (v[i])
      for (int j=i*2; j<n; j+=i)
        v[j] = 0;
  // v.erase(remove(ALL(v),0),v.end()); // ツつアツつアツづーツづつつッツづェツづ篠素ツ青板δ環スツト
  return v;
}

int main() {
  vector<int> pr = primes(10001);
  vector<int> tw(10001);
  for(int i = 5; i<10001; ++i) {
    if (pr[i] && pr[i-2]) tw[i] = i;
    else tw[i] = tw[i-1];
  }
  int n;
  while(cin >> n,n) {
    cout << tw[n]-2 << " " << tw[n] << endl;
  }
}

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(10000);
		so.clear();
		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;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;

  vector<bool> prime(10005,true);
  for(i=2;i<10005;i++)if(prime[i])
    for(j=2;i*j<10005;j++)
      prime[i*j]=false;
  prime[0]=prime[1]=false;

  while(1){
    cin>>n;
    if(n==0)break;
    for(;n>0;n--)
      if(prime[n]&&prime[n-2]){
        cout<<n-2<<" "<<n<<endl;
        break;
      }
  }
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[100000],d,f,g,h,i,j;
	while(1){
		d=0;
		f=0;
		scanf("%d",&a);
		if(a==0)	break;
		for(i=2;i<=a;i++) s[i]=1;
		s[1]=0;

		for(i=2;i<=a;i++){
			if(s[i]==1){
				for(j=2;j<=a/2;j++)
					s[i*j]=0;
			}
		}
		for(i=a;i>0;i--){
			if(s[i]==1){
				if(d==0) d=i;
				else f=i;
			}
			if(d!=0&&f!=0){
				if(d-f==2)
					break;
				d=f;
			}
		}
		printf("%d %d\n",f,d);
	}
	return 0;
}

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

int main() {
	int i, k, n;
	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){
				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",i,i-2);
	}
	return 0;
}