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])
	}
}

Python: # -*- coding: utf-8 -*-
"""
"""
import sys
from sys import stdin
from bisect import bisect_right
input = stdin.readline


def create_prime_list(limit):
    """ ??¨??????????????????????????§limit?????§????´???°?????????????±???????
    https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9
    """
    x = limit**0.5
    primes = []
    nums = [x for x in range(2, limit+1)]
    while nums[0]<=x:
        primes.append(nums[0])
        current_prime = nums[0]
        nums = [x for x in nums if x%current_prime != 0]
    primes.extend(nums)
    return primes


def main(args):
    # ??????????´???°?????????
    primes = create_prime_list(10000)
    twin_primes = []


    # prev = primes[0]
    # for p in primes[1:]:
    #     if p == prev + 2:
    #         twin_primes.append([prev, p])
    #     prev = p
    #
    # keys = [x[1] for x in twin_primes]
    # while True:
    #     n = int(input())
    #     if n == 0:
    #         break
    #     r = bisect_right(keys, n)
    #     print(*twin_primes[r-1])

    prev = primes[0]
    for p in primes[1:]:
         if p == prev + 2:
             twin_primes.append(p)
         prev = p

    while True:
        n = int(input())
        if n == 0:
            break
        r = bisect_right(twin_primes, n)
        print(twin_primes[r-1]-2, twin_primes[r-1])



if __name__ == '__main__':
    main(sys.argv[1:])

Python: n=1000000
p=[1]*(n+1)
p[0],p[1]=0,0
for i in range(2,int(n**0.5)+1):
    if p[i]:        
        for j in range(i*i,n+1,i):
            p[j]=0
#p=[i for i in range(n+1) if p[i]==1]
while 1:
    n=int(input())
    if n==0: break
    for i in range(n,2,-1):
        if (p[i],p[i-2])==(1,1):
            print(i-2,i)
            break

Python: from itertools import takewhile
pnum, tmp = [], [int(i) for i in range(2, 10000)]
while tmp[0] < 101:
    v = tmp.pop(0)
    pnum.append(v)
    tmp = list(filter(lambda x: x%v!=0, tmp))
for t in tmp: pnum.append(t)
del pnum[0:2]
while True:
    n = int(input())
    if n==0: break
    prime = list(takewhile(lambda x: x<n, pnum))
    for i in range(len(prime))[:0:-1]:
        if prime[i]-prime[i-1]==2:
            print(prime[i-1], prime[i])
            break

Python: def primes(n):
  tf = [True] * (n + 1)
  tf[0] = tf[1] = False
  for i in range(2, int(n ** (1 / 2)) + 1):
    if tf[i]:
      for j in range(i ** 2, n + 1, i):
        tf[j] = False
  return [i for i in range(n + 1) if tf[i]]

def add_twin(prime_lst, twin_lst):
  prime_lst2 = prime_lst[1:]
  for x, y in zip(prime_lst, prime_lst2):
    if y - x == 2:
      twin_lst.append(y)

def search_twin(x, twin_lst):
  left = 0
  right = len(twin_lst)
  while left + 1 < right:
    mid = (left + right) // 2
    if twin_lst[mid] > x:
      right = mid
    elif twin_lst[mid] < x:
      left = mid
    else:
      return x
  return twin_lst[left]

prime_lst = primes(10000)
twin_lst = []
add_twin(prime_lst, twin_lst)

while True:
  n = int(input())
  if n == 0:
    break
  a = search_twin(n, twin_lst)
  print(a - 2, a)

Python: # AOJ 0150 Twin Prime
# Python3 2018.6.17 bal4u

MAX = 10001
SQRT = 100     # sqrt(MAX)

prime = [True for i in range(MAX)]
def sieve():
	for i in range(4, MAX, 2):
		prime[i] = False
	for i in range(3, SQRT, 2):
		if prime[i] is True:
			for j in range(i*i, MAX, i):
				prime[j] = False
sieve()
tbl = [0]*MAX
ans = 0
for i in range(5, MAX, 2):
	if prime[i] and prime[i-2]: ans = i
	tbl[i] = ans
	
while True:
	n = int(input())
	if n == 0: break
	if (n & 1) == 0: n -= 1
	print(tbl[n]-2, tbl[n])

Python: from itertools import takewhile
pnum, tmp = [], [i for i in range(2, 10000)]
while tmp[0] < 101:
    v = tmp.pop(0)
    pnum.append(v)
    tmp = list(filter(lambda x: x%v!=0, tmp))
for t in tmp: pnum.append(t)
del pnum[0:2]
while True:
    n = int(input())
    if n==0: break
    prime = list(takewhile(lambda x: x<=n, pnum))
    for i in range(len(prime))[:0:-1]:
        if prime[i]-prime[i-1]==2:
            print(prime[i-1], prime[i])
            break

Python: MN = 10000
tp = []
op = -5
mem = [False * 2] + [True] * MN
for i in range(2, MN):
  if not mem[i]:
    continue
  if i - op == 2:
    tp.append((op, i))
  op = i
  for j in range(i + i, MN, i):
    mem[j] = False
tp.append((MN + 1, MN + 1))
while True:
  N = input()
  if not N:
    break
  for i, p in enumerate(tp):
    if p[1] > N:
      print('%d %d' % (tp[i - 1][0], tp[i - 1][1]))
      break

Python: import math

MAX = 10000


def is_prime_number(num):
    for divisor in range(3, int(math.sqrt(num) + 1), 2):
        if num % divisor == 0:
            return False

    return True


def create_prime_number_list(max):
    prime_number_list = list(range(0, max + 1))

    prime_number_list[0] = False
    prime_number_list[1] = False

    for index in range(2 * 2, max + 1, 2):
        prime_number_list[index] = False

    for num in range(3, int(math.sqrt(max + 1)), 2):

        if is_prime_number(num):
            for index in range(num * 2, max + 1, num):
                prime_number_list[index] = False

    return prime_number_list


prime_number_list = create_prime_number_list(MAX)
output = []

while True:

    num = int(input())

    if num == 0:
        break

    if num % 2 == 0:
        num -= 1

    for index in range(num, 0, -2):
        if prime_number_list[index - 2] and prime_number_list[index]:
            output.append(str(index - 2) + " " + str(index))
            break

print("\n".join(output))

Python: # Aizu Problem 00150: Twin Prime
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def primes2(n):
    """ Input n>=6, Returns a list of primes, 2 <= p < n """
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1,int(n**0.5)//3+1):
      if sieve[i]:
        k=3*i+1|1
        sieve[      k*k//3      ::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
        sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]

primes = primes2(10000)

while True:
    n = int(input())
    if n == 0:
        break
    idx = bisect.bisect_left(primes, n)
    while True:
        #if idx == len(primes):
        #    idx -= 1
        if primes[idx] >= n:
            idx -= 1
        if primes[idx] - primes[idx - 1] == 2:
            print(primes[idx - 1], primes[idx])
            break
        idx -= 1

Python: import math
m = 10000
s = [1 for i in range(m+1)]
s[0] = 0
for i in range(2, int(math.sqrt(m))+1):
    if s[i] != 0:
        for j in range(i*2, m, i):
            s[j] = 0

ss = []
for i in range(m+1):
    if s[i] == 1:
      ss.append(i)
ss.reverse()

while True:
    n = int(input())
    if n == 0:
        quit()
    for i in range(len(ss)):
        if ss[i] <= n and ss[i] - ss[i+1] == 2:
            print(ss[i+1], ss[i])
            break