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: def isPrime(n):
    for i in range(2,int(n**.5+1)):
        if n%i==0:
            return False
    return True
while 1:
    n=int(input())
    if not n:break
    for i in range(n,1,-1):
        if isPrime(i) and isPrime(i-2):
            print(i-2,i)
            break

Python: # AOJ 0150 Twin Prime
# Python3 2018.6.17 bal4u

MAX = 10001
SQRT = 100     # sqrt(MAX)

prime = [True]*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, ans = [0]*MAX, 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: # 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(10050)

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: P = []
for n in range(10000):
    p = 3
    c = 0
    if n % 2 == 0:
        c += 1
    else:
        while p < int(n**0.5) + 1:
            if n % p != 0:
                p += 2
            else:
                c += 1
                break
    if c == 0:
        P.append(n)

P.reverse()

while 1:
        j = 0
        n = int(input())
        if n == 0:
            break
        else:
            for i in range(len(P)):
                if n >= P[i]:
                    j = i
                    break
            while 1:
                if P[j]-2 == P[j+1]:
                    print(P[j+1],P[j])
                    break
                else:
                    j += 1

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


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

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: 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

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

isPrime = [True] * 10001
primes = []
def eratos(n):
    isPrime[0] = isPrime[1] = False
    for i in range(2,int(math.sqrt(n))):
        if isPrime[i]:
            j = 2 * i
            while j <= n:
                isPrime[j] = False
                j = j + i
    for i in range(2,10000):
        if isPrime[i]:
            primes.append(i)
eratos(10000)

while True:
    try:
        n = int(input())
        if n == 0:
            break
        for i in range(n,2,-1):
            if isPrime[i]:
                if isPrime[i - 2]:
                    print(i - 2,i)
                    break
    except EOFError:
        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, -1) if tf[i]]

def search_twin(prime_lst):
  prime_lst2 = prime_lst[1:]
  for x, y in zip(prime_lst, prime_lst2):
    if x - y == 2:
      return (y, x)

while True:
  n = int(input())
  if n == 0:
    break
  prime_lst = primes(n)
  print(*search_twin(prime_lst))

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