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<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int n,flg,i,j,p1,q1,fllg,ii;
	while(1){
		cin>>n;
		if(n==0)break;
		for(i=n;i>1;i--){
			flg=1;
			if(i!=2&&i%2!=0){
				for(j=2;j<i;j++){
					if(i%j==0){
						flg=0;
						break;
					}
				}
				if(flg==1){
					ii=i-2;
					for(j=2;j<ii;j++){
						if(ii%j==0){
							flg=0;
							break;
						}
					}
				}
				if(flg==1) flg=2;
			}
			if(flg==2){
				p1=ii;
				q1=i;
				break;
			}
		}
		cout<<p1<<' '<<q1<<endl;
		p1=0; q1=0;
	}
	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 number[10000+2]={0};
  int n ,i , fir ,sec;
  for(i=2 ; i<10000 ;i++){
    number[i] = isprime(i);
  }
  while(scanf("%d" ,&n)){
    if(n==0)break;
    fir = 0 ,sec = 0;
    for(i=n ;i>3 ;i--){
      if(number[i] && number[i-2]){
        fir = i-2;
        sec = i;
        break;
      }
    }
    printf("%d %d\n" ,fir ,sec);
  }
  return 0;
}

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

int	Prime(int	x){
	int	n;
	if(x	==	2)return	1;
	if(x	<	2	||	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	=	0;	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;
	}
	
		
	if(max	!=	0)printf("%d %d\n",	data[max - 1],	data[max]);
	return	0;
}

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

using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; ++i)
using ll = long long;

vector<int> ans;
void solve(int n){
    int idx = lower_bound(ans.begin(), ans.end(), n+1)-ans.begin();
    --idx;
    cout<<ans[idx]-2<<" "<<ans[idx]<<endl;
}

int main(){
    vector<int> isprime(12345,1);
    isprime[1]=isprime[0]=false;
    for(int i = 2 ; i <=10000 ; ++i){
        if(!isprime[i])continue;
        if(isprime[i-2])ans.push_back(i);
        for(int j = 2 * i ; j <= 10000 ; j+=i){
            isprime[j]=false;
        }
    }
    int n;
    while(cin>>n,n!=0)solve(n);
}

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

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

long int a[10001];

int main(){

  for(long int i=2;i*i<10001;i++){
    if( !a[i] ){
      for(long int j=i+i;j<10001;j+=i) a[j] = 1;
    }
  }

  a[0] = a[1] = 1;

  long int n;

  while(cin >> n, n){

    for(long int i=n;i>4;i--){
      if(a[i] == 0 && a[i-2] == 0){
	cout << i-2 << " " << i << endl;
	break;
      }
    }

  }

}

C++: // Tazoe

#include <iostream>
using namespace std;

void eratos(bool prime[], int n)
{
	if(n>=1){
		prime[0] = false;
	}
	if(n>=2){
		prime[1] = false;
	}

	for(int i=2; i<n; i++){
		prime[i] = true;
	}

	for(int i=2; i*i<n; i++){
		if(!prime[i])
			continue;

		for(int j=i+i; j<n; j+=i){
			prime[j] = false;
		}
	}
}

int main()
{
	bool P[10001];
	eratos(P, 10001);

	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		for(int i=n; i>=5; i--){
			if(P[i]&&P[i-2]){
				cout << i-2 << ' ' << i << '\n';
				break;
			}
		}
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cmath>

std::vector<bool> Eratosthenes(const int n){
    std::vector<bool> primes(n, true);
    primes[0] = primes[1] = false;

    for(int i=2; i<std::sqrt(n); ++i){
        if(!primes[i])
            continue;
        for(int j=i*i; j<n; j+=i)
            primes[j] = false;
    }
    return primes;
}

void MaximumTwinPrimes(const std::vector<bool> &primes){
    for(int i=primes.size()-1; i>=2; --i){
        if(primes[i] && primes[i-2]){
            std::cout << i-2 << " " << i << std::endl;
            return;
        }
    }
}

int main(){
    int n;
    while((std::cin >> n) && n > 0){
        std::vector<bool> primes = Eratosthenes(n);
        MaximumTwinPrimes(primes);
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PA;
int main(){
  bool sosu[10001];
  PA p,sou[10001];
  for(int i=3;i<=10000;i+=2){
    for(int j=i*i;j<=10000&&sosu[i]==false;j+=i)
      sosu[j] = true;
    if(sosu[i-2] == false && sosu[i] == false)
      p = PA(i-2,i);
    sou[i] = p;
  }
  int a;
  while(cin>>a,a!=0){
    if(a%2 == 0) a--;
    cout << sou[a].first << ' ' << sou[a].second << endl;
  }  
  return (0);
}

C++: #include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;



int main(){
	int dt[10003];
	dt[0]=dt[1]=0;
	loop(i,2,10003)dt[i]=1;
	dt[10001]=dt[10002]=0;
	for(int i=2;i<100;i++){
		if(dt[i]==1){
			for(int j=2;i*j<10000;j++){
				dt[i*j]=0;
			}
		}
	}
	int n;
	while(1){
		cin>>n;
		if(n==0)break;
		int ans=0;
		rep(i,n-2){
			if(dt[i]==1 && dt[i+2]==1){
				ans=i;
			}
		}
		cout<<ans<<" "<<ans+2<<endl;
	}
	return 0;
}

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

using namespace std;

int s[10001];

void sieve() {
    for(int i = 0; i < 10001; i++) s[i] = 1;
    s[0] = s[1] = 0;

    for(int i = 2; i <= sqrt(10001); i++) {
        if(s[i]) {
            for(int j = i * i; j < 10001; j += i) {
                s[j] = 0;
            }
        }
    }
}

int tabs(int a) {
    return a > 0 ? a : -a;
}

int main() {
    sieve();
    int n;
    while(~scanf("%d", &n)) {
        if(n == 0) break;
        for(int i = n; i >= 2; i--) {
            for(int j = i; j >= 2; j--) {
                if(s[i] && s[j] && tabs(i - j) == 2) {
                    printf("%d %d\n", j, i);
                    goto end;
                }
            }
        }
        end:;
    }
}

C++: //Name: Twin Prime
//Level: 2
//Category: 数学,素数
//Note: 

/**
 * 10000以下の双子素数を列挙しておけば、あとは線形探索でよい。
 *
 * オーダーは O(M log log M)。
 * ただしMは求める必要がある最大の素数で、M=10000。
 */
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

vector<bool> eratosthenes(int N) {
    vector<bool> is_prime(N+1, true);
    is_prime[0] = is_prime[1] = false;

    const int LIM = static_cast<int>(sqrt(N));
    for(long long i = 2; i <= LIM; ++i) {
        if(is_prime[i]) {
            for(long long j = i*i; j <= N; j += i) {
                is_prime[j] = false;
            }
        }
    }
    return is_prime;
}

bool solve(bool first) {
    const static auto is_prime = eratosthenes(10000);

    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;
    for(int i = N; i >= 0; --i) {
        if(is_prime[i] && is_prime[i-2]) {
            cout << i-2 << ' ' << i << endl;
            break;
        }
    }

    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

    bool first = true;
    while(solve(first)) {
        first = false;
    }
    return 0;
}