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<algorithm>
#include<vector>
#include<cstring>
using namespace std;


#define MAX_N 10000
int prime[MAX_N];
bool is_prime[MAX_N+1];
int sieve(int n){
	int p=0;
	memset(is_prime,true,sizeof(is_prime));
	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);
	vector<int> p;
	for(int i=2;i<=MAX_N-2;i++)
		if(is_prime[i]&&is_prime[i+2])p.push_back(i+2);
	int n;
	while(cin>>n&&n){
		int a=upper_bound(p.begin(),p.end(),n)-p.begin();
		cout<<p[a-1]-2<<' '<<p[a-1]<<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,p1,q1,i1 = 0,i2 = 0,max = 0,k;
  while(1){
    scanf("%d",&n);
    if(n == 0){
      break;
    }
    for(k = 0;k + 2 < n;k++){
      i1 = isprime(k);
      i2 = isprime(k + 2);
      if(i1 == 1 && i2 == 1){
        max = k;
      }
    }
    p1 = max;
    q1 = max + 2;
    printf("%d%d\n",p1,q1);
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  //ツ素ツ青板青カツ青ャ
  const int NUM = 10001;
  bool prime[NUM];
  prime[0] = false;
  prime[1] = false;
  for(int i=2;i<NUM;i++)
    prime[i] = true;
  for(int i=2;i*i<NUM;i++)
    for(int k=2;i*k<NUM;k++)
      prime[i*k]=false;

  int maxtwin[10001],twin;
  for(int i=5;i<10001;i++){
    if(prime[i]&&prime[i-2])twin = i;
    maxtwin[i]=twin;
  }
  for(int n;cin>>n,n;){
    cout<<maxtwin[n]-2<<" "<<maxtwin[n]<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    std::deque<int> arr(10001,1);
    std::deque<int> prime;
    arr[0]=0;
    arr[1]=1;
    for (int i=2;i*i<10000;i++) {
        if (arr[i]==1) {
            for (int j=i*i;j<10000;j+=i) {
                arr[j]=0;
            }
        }
    }
    for (int k=2;k<=10000;k++) {
        if (arr[k]==1) {
            prime.emplace_back(k);
        }
    }
    int n;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            auto itr=upper_bound(prime.begin(),prime.end(),n);
            int dis=distance(prime.begin(),itr);
            dis--;
            for (int l=dis;l>0;l--) {
               if (prime[l]-prime[l-1]==2) {
                    cout<<prime[l-1]<<" "<<prime[l]<<endl;
                    break;
                }
            }
        }
    }
}

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

bool isPrime(int n)
{
	if (n % 2 == 0) return false;
	for (int i = 3; i < n; i += 2){
		if (n % i == 0) return false;
	}
	return true;
}

int main(void)
{
	int n;
	while (scanf("%d", &n), n){
		
		for (int i = n; 5 <= i; i--){
			// cout << i << endl;
			if (isPrime(i) && isPrime(i-2)){
				cout << i-2 << " " << i << endl;
				break;
			}
		}
		
	}
	
	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;
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(i=n;i>=5;i--){
			if(isprime(i)==1&&isprime(i-2)==1){
				printf("%d %d\n",i-2,i);
				break;
			}
		}
	}
	return 0;
}

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

bool isPrime(int x){
	for(int i=2;i*i<=x;i++){
		if(x % i == 0){
			return false;
		}
	}
	return true;
}

int main(void){
	int n;

	while(cin>>n,n){
		for(int i=n;;i--){
			if(isPrime(i) && isPrime(i-2)){
				cout<<i-2<<" "<<i<<endl;
				break;
			}
		}
	}

	return 0;
}

C++: #include<stdio.h>
#include<math.h>

int isprime(int n){
  int i;
  for(i = 2; i * i <= n; i++){
    if(n % i == 0) return 0;
  }
  return 1;
 }

int	main(){
	int	n,	i,	a,	b,	max,	data[10000];
	while(1){
	  a	=	0;
	  b	=	0;
	  max	=	0;
	  scanf("%d",	&n);
	  if(n	==	0) break;
	  for(i	=	n;	i	>=	1;	i--){
		  if(isprime(i)	==	1){
			  a	=	b;
			  b	=	i;
		  }
		  if(a	-	b	==	2)break;
		}
//		for(i	=	1;	i	<=	cnt;	i++){
//			if(data[i]	-	data[i	-	1]	==	2)max	=	i;
//		}
		printf("%d %d\n",	b,	a);
	}
	return	0;
}

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

const int MAX = 100001;
char p[MAX] = {0};

int main(){
	for(int i=2 ; i < MAX ; i++ ) p[i] = 1;
	for(int i=2 ; i*i < MAX ; i++ ){
		if( p[i] ){
			for(int j=i+i ; j < MAX ; j += i ){
				p[j] = 0;
			}
		}
	}
	
	int n;
	while( cin >> n , n ){
		int a, b;
		for(int i=2 ; i <= n ; i++ ){
			if( p[i-2] && p[i] ){
				a = i-2;
				b = i;
			}
		}
		cout << a << " " << b << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int maxsize(0);
	vector<int> input;

	while (1)
	{
		int tmp;

		cin >> tmp;

		if (!tmp)
		{
			break;
		}

		input.push_back(tmp);

		(maxsize < tmp) ? (maxsize = tmp) : (0);
	}

	vector<int> prime, ans;

	for (int i(2); i <= maxsize; ++i)
	{
		for (vector<int>::iterator i2(prime.begin()), n2(prime.end()); i2 != n2; ++i2)
		{
			if ((i % *i2) == 0)
			{
				goto nx;
			}
		}

		prime.push_back(i);
		if (lower_bound(prime.begin(), prime.end(), i) != prime.end())
		{
			ans.push_back(i);
		}
		nx:;
	}

	for (vector<int>::iterator i(input.begin()), n(input.end()); i != n; ++i)
	{
		int out(*i);

		for (vector<int>::reverse_iterator i2(ans.rbegin()), n2(ans.rend()); i2 != n2; ++i2)
		{
			if (*i2 <= out)
			{
				cout << (*i2 - 2) << ' ' << (*i2) << endl;
				break;
			}
		}
	}

	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;

int prime[10000];
bool is_prime[10001];

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

	return p;
}

signed main()
{
	int n;

	int p = sieve();

	while (true)
	{
		cin >> n;
		if (n == 0) break;

		int mx, mn;
		for (int i=0; i<p; i++)
		{
			if (prime[i + 1] > n) break;
			if (prime[i] + 2 == prime[i+1])
			{
				mx = prime[i + 1];
				mn = prime[i];
			}
		}

		cout << mn << " " << mx << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
bool sosu(int q);
int mem[10005]={0};
main(){
  int n;
  while(1){
    cin>>n;
    if(n==0) break;
    int q;
    for(q=n-((n+1)%2);q-2>1;q-=2){
      if(sosu(q)&&sosu(q-2)){
	cout<<q-2<<" "<<q<<endl;
	break;
      }
    }
  }
}
bool sosu(int q){
  if(mem[q]==1){
    return 1;
  }
  else if(mem[q]==-1){
    return 0;
  }
  else{
    for(int i=3;i<=sqrt(q);i+=2){
      if(mem[i]==0||mem[i]==1){
	for(int j=i;j<=q;j+=i){
	  mem[j]=0;
	  if(j==q){
	    return 0;
	  }
	}
      }
    }
    if(mem[q]==0){
      mem[q]=1;
      return 1;
    }
  }
}