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<stdio.h>
#include<math.h>

int	Prime(int	x){
	int	n;
	if(x	==	2)return	1;
	if(x	%	2	==	0)return	0;
	for(n	=	3;	n	<=	sqrt((double)x);	n	+=	2){
		if(x	%	n	==	0)return	0;
	}
	return	1;
}

int	main(){
	int	n,	i,	cnt	=	0,	max	=	0,	data[100];
	scanf("%d",	&n);
	for(i	=	2;	i	<=	n;	i++){
		if(Prime(i)	==	1){
			data[cnt]	=	i;

			cnt++;
		}	
	}
	for(i	=	1;	i	<=	cnt;	i++){
		if(data[i]	-	data[i	-	1]	==	2)max	=	i;
	}
	
		
		
	printf("%d %d\n",	data[max - 1],	data[max]);
	return	0;
}

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,n){
		solve(n);
	}
}

C++: #include <stdio.h>
#include <math.h>
#include <string>
int isprime(int n) {
	int i;
	if(n<=1){
		return 0;
	}
	for(i = 2; i*i<=n; i++) {
		if(n % i == 0){
			return 0;
		}
	}
	return 1;
}

int main(){
	int n,i;
	
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(i = n;i>=2;i--){
			if(isprime(i)&&isprime(i-2)){
				printf("%d %d",i-2,i);
				break;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
vector<int>prime;
int main(){
    int ask;
    prime.push_back(1);
    prime.push_back(2);
    for(int i=3;i<10001;i++){
        int t=1;
        for(int j=2;j*j<=i;j++){
            if(i%j==0){
                t=0;
                break;
            }
        }
        
        if(t)
            prime.push_back(i);
    }
    while(true){
        cin>>ask;
        if(ask==0)
            break;
        for(int i=ask;i>1;i--){
            if(find(prime.begin(),prime.end(),i)!=prime.end()&&find(prime.begin(),prime.end(),i-2)!=prime.end()){
                cout<<i-2<<" "<<i<<endl;
                break;
            }
        }
    }
    return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

constexpr int LIM = 10006;

char isprime[LIM];
int twinprime[LIM];

void setprime() {
    fill(isprime, isprime+LIM, 1);
    isprime[0] = isprime[1] = 0;
    for (int x = 2; x * x < LIM; ++x) {
        if (isprime[x]) {
            for (int y = x * x; y < LIM; y += x) {
                isprime[y] = 0;
            }
        }
    }
    for (int x = 5; x < LIM; ++x) {
        if (isprime[x-2] && isprime[x]) {
            twinprime[x] = x;
        } else {
            twinprime[x] = twinprime[x-1];
        }
    }
}

bool solve() {
    int n;
    cin >> n;
    if (n == 0) { return false; }
    int ans = twinprime[n];
    cout << (ans - 2) << ' ' << ans << endl;
    return true;
}

int main() {
    setprime();
    while(solve());
    return 0;
}

C++: #include<stdio.h>
const int MAX_V = 10000;
int main(){
	int i, k, n =10, cnt = 0, idx = 2;
	int prime[MAX_V+1];
	int border[10];
	int maxprime[10] = {0};
	int difference[MAX_V+1];
	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;
			}
		}
	}
	for( i = 2; i < MAX_V; i++){
		if(prime[i] == 1){
			difference[i] = i - idx;
			idx = i;
		}
	}
	for( i = 0; i < n; i++){
		scanf("%d", &border[i]);
		if( border[i] <5 || border[i] 
		if(border[i] == 0) break;
		cnt++;
	}
	
	for( i = 0; i < cnt; i++){
		for( k = 2; k <= border[i]; k++){
			if( difference[k] == 2 && k > maxprime[i]){
				maxprime[i] = k;
			}
		}
		printf("%d %d\n", maxprime[i] - 2, maxprime[i]);
	}
	return 0;
}

C++: #include <cmath>
 #include <cstring>
 #include <iostream>
 #include <ostream>
 #include <vector>
   
 using std::cin;
 using std::cout;
 using std::cerr;
 using std::endl;
   
 // n 以下の素数のリストを返す O(nlog(log(n)))
 std::vector<int> eratosthenes(int n) {
   std::vector<int> is_prime(n + 1, 1);
   std::vector<int> primes;
  
   is_prime[0] = is_prime[1] = 0;
   primes.push_back(2);
   for(int i = 3; i <= n; i += 2) {
     if(is_prime[i]) {
       primes.push_back(i);
       for(int j = 3; i * j <= n; j += 2) {
         is_prime[i * j] = 0;
       }
     }
   }
  
   return primes;
 }
   
 int main() {
   int n;
   std::vector<int> primes = eratosthenes(10000);
   
   while(cin >> n, n) {
     int a = 2, b = 3;
     for(int i = 1; i < primes.size(); i++) {
       if (primes[i] > n) break;
  
       if(primes[i] - primes[i - 1] == 2) {
         a = primes[i - 1];
         b = primes[i];
       }
     }
     cout << a << " " << b << endl;
   }
   
   return 0;
 }

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

int main(){
  constexpr int M = 10001;
  vector<bool> P(M,true);
  for(int i = 2; i*i < M; ++i){
    if(not P[i]) continue;
    for(int j = i; i*j < M; ++j){
      P[i*j] = false;
    }
  }
  vector<int> A(M,-1);
  for(int i = 5; i < M; ++i){
    if(not P[i]) A[i] = A[i-1];
    else if(P[i-2]) A[i] = i;
    else A[i] = A[i-1];
  }
  int n;
  while(cin >> n,n){
    cout << A[n]-2 << " " << A[n] << endl;
  }
}

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

bool furui[10010];
vector<int> prime;
vector<int> twin;

void mkprime() {
	for(int i = 0; i < 10010; i++) furui[i] = true;
	furui[0] = furui[1] = false;
	for(int i = 0; i < 10010; i++) {
		if(furui[i]) {
			prime.push_back(i);
			for(int j = i * 2; j < 10010; j += i) {
				furui[j] = false;
			}
		}
	}
	for(int i = 0; i < prime.size() - 1; i++) {
		if(prime[i + 1] - prime[i] == 2)
			twin.push_back(prime[i + 1]);
	}
	sort(twin.begin(), twin.end());
}

int main() {
	int n;
	mkprime();
	while(cin >> n, n) {
		vector<int>::iterator iter;
		iter = upper_bound(twin.begin(), twin.end(), n);
		cout << *(iter-1) - 2 << " " << *(iter-1) << endl;
	}
}

C++: #include <stdio.h>
int main(){
	int i,j;
	int isprime[10000];
	for(i=0;i<=10000;i++){
 		isprime[i]=1;
	}
	isprime[0]=isprime[1]=0;
	for(i=2;i<=10000;i++){
 		if(isprime[i]==1){
 			for(j=2*i;j<=1000;j+=i){
				isprime[j]=0;
			}
		}
	}
	int n,p1,q1;
	scanf("%d", &n);
	while (n != 0){
		for(i=2;i<=n;i++){
			if(isprime[i-2]==1 && isprime[i]==1){
				p1 = i-2;
				q1 = i;
			}
		}
		printf("%d %d\n",p1,q1);
		scanf("%d", &n);
	}
	return 0;
 }