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>
#include<set>

using namespace std;

int main()
{
	int n;
	int i,j,k;
	int num[60000];
	int pri[100000];
	set<int> prime;
	
	pri[0]=2;
	
	for(i=0;i<60000;i++)
		num[i]=1;
	
	num[0]=0;
	num[1]=0;
	for(i=0;pri[i]<50022;)
	{
		for(j=1;pri[i]*j<50100;j++)
		{
			num[pri[i]*j]=0;
//			cout << "*" << pri[i]*j << endl;
		}
		for(k=0;;k++)
		{
			if(num[k]==1)
			{
//				cout << "pri:" << pri[i] << endl;;
				i++;
				pri[i]=k;
//				cout << k <<endl;
				break;
			}
		}
	}
	
	
	for(j=0;j<i;j++)
		prime.insert(pri[j]);
		
	set<int>::iterator it=prime.begin();
	for(;it!=prime.end();)
	{
//		cout << "it: " << *it << endl;
		it++;
	}
	for(;cin >> n;)
	{
	
		it=prime.lower_bound(n);
		if(*it==n)
		{
			cout << *(--it) << " " ;
			++it;
			cout << *(++it) << endl;
		}
		else
		{
			cout << *(--it) << " ";
			++it;
			cout << *(it) << endl;
		}
	}
}

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

namespace _0044
{
    class Program
    {
        static void Main(string[] args)
        {
            var primeList = new List<int>();
            for (int i = 1; i < 50022; i++)
            {
                if (IsPrime(i))
                {
                    primeList.Add(i);
                }
            }

            while (true)
            {
                var input = Console.ReadLine();

                if (string.IsNullOrEmpty(input)) { break; }

                var number = int.Parse(input);
                var previousPrimeNumber = 0;
                var nextPrimeNumber = 0;

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

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

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

bool is_composite[100001];
vector<int> primes;

int main() {
  for (int i=2; i<=100000; i++) {
    if (!is_composite[i]) {
      primes.push_back(i);
      for (int j=i+i; j<=100000; j+=i) is_composite[j] = true;
    }
  }

  while (1) {
    int n;
    if (scanf("%d", &n) != 1) return 0;
    auto itr1 = lower_bound(primes.begin(), primes.end(), n)-1;
    auto itr2 = upper_bound(primes.begin(), primes.end(), n);
    printf("%d %d\n", *itr1, *itr2);
  }
}

C++: #include <iostream>
using namespace std;
int p[50100];
int main()
{
  int i,j;
  for(i=2;i*i<50100;i++){
    if(p[i]==0){
      for(j=i*2;j<50100;j+=i){
	p[j] = 1;
      }
    }
  }
  while(cin >> i,i){
    for(j=i-1;p[j];j--){}
    cout << j << ' ';
    for(j=i+1;p[j];j++){}
    cout << j << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cmath>
#include <algorithm>
#define MAX_NUM 100000

using namespace std;

int main(void){
	int n, i, j;
	bool f[MAX_NUM + 1];
	fill(f,f + MAX_NUM + 1,true);
	for(i = 2;i <= sqrt((double)MAX_NUM);i++){
		for(j = i * 2;j <= MAX_NUM;j+=i){
			f[j] = false;
		}
	}
	while(scanf("%d",&n) != EOF){
		for(i = n - 1;!f[i];i--);
		printf("%d ",i);
		for(i = n + 1;!f[i];i++);
		printf("%d\n",i);
	}
	return 0;
}

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

vector<int> sieve(int n);

vector<int> sieve(int n){
    vector<int> primes(n);
    for(int i=2; i<n; i++){
        primes[i] = i;
    }
    for(int i=2; i*i<n; i++){
        if(primes[i]){
            for(int j=i*i; j<n; j+=i){
                primes[j] = 0;
            }
        }
    }
    return primes;
}

int main(){
    vector<int> primes = sieve(50022);
    int n;
    while(cin >> n){
       int lower = n-1;
       int upper = n+1;
       while(primes[lower] == 0) lower--;
       while(primes[upper] == 0) upper++;
       cout << primes[lower] << " " << primes[upper] << endl;
    }
    return 0;
}

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

int main(){
	bool b[MAX];
	fill(b, b+MAX, false);b[0] = b[1] = true;
	for(int i = 2;i < MAX;i++){
		if(!b[i]){
			for(int j = 2;i*j < MAX;j++){
				b[i*j] = true;
			}
		}
	}
	
	int n, x, y;
	while(cin >> n){
		for(x = n-1;b[x];x--);
		for(y = n+1;b[y];y++);
		cout << x << " " << y << endl;
	}
	return 0;
}
/*
1
y eazqyp pnop pngtg ye obmpngt xmybp mr lygw
*/

C++: #include<iostream>
#include<cmath>
#define Int int
using namespace std;
 
const int MAX_NUM = 500000;
bool prime_number[MAX_NUM];
  
void isPrime() {
    fill(prime_number, prime_number + MAX_NUM, true);
    prime_number[0] = prime_number[1] = false;
  
    for(int i = 2; i < MAX_NUM; i++) {
        if(prime_number[i])
        for(int j = 2; i*j < MAX_NUM; j++) {
            prime_number[i*j] = false;
        }
    }
}
int main(void){
  int n;
  isPrime();
  while(cin>>n){
    int i;
 
    for(i = (!prime_number[n]?n:n-1) ; !prime_number[i] ; i --);
    cout<<i<<" ";
    for(i = (!prime_number[n]?n:n+1) ; !prime_number[i] ; i ++);
    cout<<i<<endl;
  }
}

C++: #include <iostream>

using namespace std;

int main()
{
	int prnum[50001] = { 0 }, n;

	for (int i = 2; i < 50001; i++) {
		if (!(prnum[i])) {
			for (int j = i*2; j < 50001; j+=i) {
				prnum[j] = 1;
			}
		}
	}

	while (1) {
		cin >> n;
		if (cin.eof()) break;

		for (int i = n-1;; i--) {
			if (!(prnum[i])) {
				cout << i << " ";
				break;
			}
		}
		for (int i = n+1;; i++) {
			if (!(prnum[i])) {
				cout << i << endl;
				break;
			}
		}
	}

}

C++: #include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int lis[100000];
int main(){
    for(int i=2;i<100000;i++)lis[i]=1;
    for(int i=2;i<330;i++){
        if(lis[i]){
            for(int j=2;;j++){
                if(100000<=i*j)break;
                lis[i*j]=0;
            }
        }
    }
    int a;
    while(cin>>a){
        for(int i=-1;;i--){
            if(lis[a+i]){
                cout<<a+i;
                break;
            }
        }
        cout<<" ";
        for(int i=1;;i++){
            if(lis[a+i]){
                cout<<a+i;
                break;
            }
        }
        cout<<endl;
    }
    return 0;
}