Go: package main

import (
    "fmt"
    "bufio"
    "os"
    "strconv"
)

const MAX = 60000
const ROOT = 250

var sc =  bufio.NewScanner(os.Stdin)

func main() {
    var isPrime [MAX]bool
    for i := 2;i < MAX; i++ {
        isPrime[i] = true
    }
    for i := 2;i < ROOT; i++ {
        if isPrime[i] {
            for j := i * i;j < MAX; j+=i {
                isPrime[j] = false
            }
        }
    }
    var minPrime [MAX]int
    var maxPrime [MAX]int
    min := -1
    for i := 0;i < MAX; i++ {
        minPrime[i] = min
        if isPrime[i] {
            min = i
        }
    }
    max := -1
    for i := MAX - 1; i >= 0; i-- {
        maxPrime[i] = max
        if isPrime[i] {
            max = i
        }
    }

    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Printf("%d %d\n", minPrime[n], maxPrime[n])
    }
}

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

int main(){
  int n;
  while(cin >> n,n){
    int max=0;
    for(int i=1; i<n; ++i){
      if(i%2==0){break;}
      bool frg = true;
      for(int j=2; j*j<i; ++j){
        if(i%j==0){frg=false; break;}
      }
      if(frg && max<i){max=i;}
    }
    cout << max << " ";
    for(int i=n+1; i<2*n; ++i){
      if(i%2==0){break;}
      bool frg = true;
      for(int j=2; j*j<i; ++j){
        if(i%j==0){frg=false; break;}
      }
      if(frg){cout << i << endl;break;}
    }
  }
  return 0;
}

C++: using System;
using System.Collections.Generic;

namespace _0044
{
    class Programｓ
    {
        readonly static int MAX_NUMBER = 50022;

        static void Main(string[] args)
        {
            List<int> primeList = new List<int>();
            for (int i = 1; i < MAX_NUMBER; i++)
            {
                if (IsPrime(i))
                {
                    primeList.Add(i);
                }
            }

            while (true)
            {
                var input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) { break; }
                int number = int.Parse(input);
                int previousPrimeNumber = 0;
                int nextPrimeNumber = 0;

                foreach (var primeNumber in primeList)
                {
                    if (primeNumber < number)
                    {
                        previousPrimeNumber = primeNumber;
                    }
                    else if (primeNumber > number)
                    {
                        nextPrimeNumber = primeNumber;
                    }

                    if (nextPrimeNumber != 0)
                    {
                        break;
                    }
                }
                Console.WriteLine("{0} {1}", previousPrimeNumber, nextPrimeNumber);
            }
        }

        static bool IsPrime(int number)
        {
            if (number <= 1)
            {
                return false;
            }
            else if (number <= 3)
            {
                return true;
            }
            else if ((number % 2) == 0)
            {
                return false;
            }
            else
            {
                for (int i = 3; i <= (int)Math.Sqrt(number); i += 2)
                {
                    if (number % i == 0)
                    {
                        return false;
                    }
                }
            }
            return true;
        }
    }
}

C++: #include <iostream>
#include <cstring>
using namespace std;
int main(){
	int n,m;
	bool f[50001];
	memset(f,true,sizeof(f));
	for(int i=2;i<50001;i++){
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				f[i]=false;
				break;
			}
		}
	}
	while(cin>>n){
		for(int i=n-1;i>2;i--){
			if(f[i]){
				cout<<i<<" ";
				break;
			}
		}
		for(int i=n+1;i<50001;i++){
			if(f[i]){
				cout<<i<<endl;
				break;
			}
		}
	}
}

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

int main(){
  int table[50001];
  for(int i=2; i<1000; ++i){
    if(!table[i]){
      for(int j=i*2; j<=50001; j+=i){
        table[j]=1;
      }
    }
  }
  int n;
  while(cin >> n,n){
    int i;
    for(i=n-1; table[i]; --i);
    cout << i << " ";
    for(i=n+1; table[i]; ++i);
    cout << i << endl;
  }
return 0;
}

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

bool isprime(int n) {
	if (n==2 || n==3) return true;
	if (!(n%2)) return false;
	if (!(n%3)) return false;
	int lim = (int)sqrt((double)n) + 1;
	for (int i = 6; i <= lim; i += 6) {
		if (!(n%(i-1))) return false;
		if (!(n%(i+1))) return false;
	}
	return true;
}

int main() {
	int n;
	while (cin >> n) {
		int k;
		for (k = n-1; !isprime(k); k--);
		cout << k;
		for (k = n+1; !isprime(k); k++);
		cout << " " << k << endl;
	}
	return 0;
}

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

int main(){
  int n;
  while(cin >> n,n){
    for(int i=n-1; i>0; --i){
      bool frg = true;
      for(int j=2; j*j<i; ++j){
        if(i%2==0){frg=false; break;}
        if(i%j==0){frg=false; break;}
      }
      if(frg){cout << i;break;}
    }
    
    cout << " ";
    
    for(int i=n+1; i<2*n ; ++i){
      bool frg = true;
      for(int j=2; j*j<i; ++j){
        if(i%2==0){frg=false; break;}
        if(i%j==0){frg=false; break;}
      }
      if(frg){cout << i << endl;break;}
    }
    
  }
  return 0;
}

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

int main()
{
	int n;
	while(cin>>n){
		int na, nb;
		bool flag = true;
		for(int i=n-1;;i--){
			for(int j=2;j*j<i;j++){
				if(i % j == 0){
				flag = false;
				break;
				}
			}
			if(flag){
			na = i;
			break;
			}
			flag = true;
		}
		
		flag = true;
		for(int i=n+1;;i++){
			for(int j=2;j*j<i;j++){
				if(i % j==0){
					flag = false;
					break;
				}
			}
			if(flag){
				nb = i;
				break;
			}
			flag = true;
		}
		
		cout<<na<<' '<<nb<<endl;
	}
	return 0;
}

C++: #include <stdio.h>
int main(){
    int n,i,f[10000],now=2;
    bool flag;
    f[0]=2;
    f[1]=3;
    for(i=5;i<50000;i+=2){
        flag=true;
        for(int j=1;f[j]*f[j]<=i&&flag;j++){
            if(i%f[j]==0)flag=false;
        }
        if(flag){
            f[now]=i;
            now++;
        }
    }
    while(scanf("%d",&n)!=EOF){
        for(i=0;f[i]<n;i++);
        if(f[i]==n)printf("%d %d\n",f[i-1],f[i+1]);
        else printf("%d %d\n",f[i-1],f[i]);
    }
}

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

bool prime[MAX];
void calcPrime(){
	for(int i = 2; i < MAX; i++) prime[i] = true;
	for(int i = 2; i < MAX; i++){
		if( prime[i] ){
			for(int j = i+i; j <= MAX; j += i){
				prime[j] = false;
			}
		}
	}
}

int main(){
	int n;
	calcPrime();
	while( cin >> n ){
		int under = -1, over = -1;
		for(int d = n-1, u = n+1; 2 < d || u < MAX; ){
			if( 2 < d ) d--;
			if( u < MAX ) u++;
			if( under != -1 && over != -1 ) break;
			if( prime[d] ) under = d;
			if( prime[u] ) over = u;
		}
		cout << under << " " << over << endl;
	}
}

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

int main()
{
	int n;
	while (cin>>n) 
	{
		bool prime[500000];
		fill(prime,prime+500000,0);
		vector<int> nums;
		for(int i = 2; i < 500000; ++i)
		{
			if(prime[i]) continue;
			nums.push_back(i);
			for(int j = i*2; j < 500000; j+=i)
			{
				prime[j]=true;
			}
		}

		vector<int>::iterator it=lower_bound(nums.begin(),nums.end(),n);
		if(*(it-1)!=n) cout<<*(it-1);
		else cout<<*(it-2);

		it=upper_bound(nums.begin(),nums.end(),n);
		cout<<" "<<*it<<endl;
	}
  return 0;
}