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++: using System;
using System.Collections.Generic;

namespace _0044
{
    class Programｓ
    {
        static void Main(string[] args)
        {
            List<int> 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; }
                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<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int ma=1e5;
  vector<bool>sosu(ma,1);
  sosu[0]=sosu[1]=0;
  for(int i=4;i<ma;i+=2)sosu[i]=0;
  for(int i=3;i<ma;i+=2)
    for(int j=i*3;j<ma;j+=i*2)sosu[j]=0;
  int in;
  while(cin>>in){
    for(int i=in-1;i>=2;i--)if(sosu[i]){cout<<i;break;}
    for(int i=in+1;i<1e6;i++)if(sosu[i]){cout<<" "<<i<<endl;break;}
  }
}

C++: #include<bits/stdc++.h>
using namespace std;

#define MAX_N 50010

int prime[MAX_N];
bool is_prime[MAX_N + 1];


void prime_generate(){
	int p = 0;
	for(int i = 0; i <= MAX_N; i++) is_prime[i] = true;

	is_prime[0] = is_prime[1] = false;

	for(int i = 2; i <= MAX_N; i++){
		if(is_prime[i]){
			prime[p++] = i;
			for(int j = 2 * i; j <= MAX_N; j += i) is_prime[j] = false;
		}
	}
}

void solve(int n){
	for(int i = 0; i < MAX_N; i++){
		if(prime[i] == n){
			cout << prime[i-1] << " " << prime[i+1] << endl;
			break;
		}
		else if(prime[i] > n){
			cout << prime[i-1] << " " << prime[i] << endl;
			break;
		}
		else continue;
	}
}

int main(){
	prime_generate();

	int n;
	while(cin >> n){
		solve(n);
	}
}

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

const int MAX = 50000;

int main ()
{
    vector<int> num(MAX + 1, 1);
    num[0] = num[1] = -1;
    for (int i = 2; i <= MAX / 2; i++) {
        for (int j = 2; i * j <= MAX; j++) {
            num[i*j] = -1;
        }
    }

    vector<int> prim;
    for (int i = 0; i < num.size(); i++) {
        if (num[i] == 1) {
            prim.push_back(i);
            num[i] = prim.size() - 1;
        }
    }

    int n;
    while (cin >> n) {
        cout << prim[num[n]-1] << " " << prim[num[n]+1] << endl;
    }

    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;
        }
    }
}



/*
 * 
 * ・最小の素数 2
 * ・最大の素数 50022
 * 
 */

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

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, u = n; 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;
	}
}