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)
        {
            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<iostream>

using namespace std;

int main(){
	int prime[50000];
	int ptr=0;
	unsigned long counter = 0;
	prime[ptr++] = 2;
	prime[ptr++] = 3;
	
	for(int no =3 ; no <= 50000 ; no += 2){
		int flag=0;
		for(int i=1 ; prime[i] * prime[i] <= no ; i++){
			counter++;
			if(no % prime[i] == 0){
				flag = 1;
				break; 
			}
		}
		if(!flag)
			prime[ptr++] = no;
	}
	
	int n;
	while(cin>>n){
		int i;
		for(i=0;i<50000;i++){
			if(n<prime[i])break;
		}
		if(n==3){
			cout<<2;
		}else{
		if(prime[i-1]==n)cout<<prime[i-2];
		else cout<<prime[i-1];
		}
		cout<<" "<<prime[i]<<endl;
	}
	
}

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

int main()
{
  bool is_prime[1000000];
  is_prime[0] = is_prime[1] = false;
  for(int i=2; i<1000000; i++){
    is_prime[i] = true;
  }

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

  while(1){
    int n;
    cin >> n;

    if(cin.eof())
      break;

    int i=n-1, j=n+1;
    while(1){
      if(is_prime[i]){
        break;
      }
      i-=1;
    }

    while(1){
      if(is_prime[j])
        break;
      j++;
    }
    cout << i << ' ' << j << endl;
  }
  return 0;
}

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

vector<int> sieveOfEratosthenes(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;
    }
  }
  // primes.erase(remove(begin(primes), end(primes), 0), end(primes));
  return primes;
}

int main() {
  int n;
  auto v = sieveOfEratosthenes(51001);
  while (cin >> n) {
    for (int i = n - 1; i >= 0; --i) {
      if (v[i]) {
        cout << v[i] << ' ';
        break;
      }
    }
    for (int i = n + 1; i <= 51000; ++i) {
      if (v[i]) {
        cout << v[i] << endl;
        break;
      }
    }
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#define MAX 1000000
using namespace std;
int main(){
    vector<bool> v(MAX);
    for(int i = 0;i<MAX;i++)
      v[i]=true;

      v[0]=v[1]=false;
    for(int i = 2;i<1000;i++){
      if(v[i]){
        for(int j=i*i;j<MAX;j+=i){
         v[j]=false;
       }
      }
    }
    while(true){
      int a;
      cin >> a;
      if(cin.eof())return 0;
      while(i=n-1){
        if(v[i]){
          cout >>i>>' ';
          break;
      }
      i--;
    }
    while(i=n+1){
      if(v[i]){
        cout >>i>>endl;
        break;
    }
    i++;
  }
}

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

#define MAX 50022

int main(void)
{
	bool p[MAX];
	vector <int> prime;
	int i, j;
	
	for (i = 0; i < MAX; i++){
		p[i] = true;
	}
	for (i = 2; i < MAX; i++){
		if (p[i]){
			prime.push_back(i);
			for (j = 1; i * j < MAX; j += 2){
				p[i * j] = false;
//				printf("%d ", i * j);
			}
		}
	}
	
	int n;
	while (cin >> n){
		if (n == EOF) return 0;
		int a, b;
		for (i = 0; i < prime.size(); i++){
			if (prime[i] < n) a = prime[i];
			if (n < prime[i]) {
				b = prime[i];
				break;
			}
		}
		printf("%d %d\n", a, b);
	}
	
	return 0;
}

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

int main(){
  int table[55000]={};
  for(int i=2; i*i<55000; ++i){
    if(!table[i]){
      for(int j=i*2; j<=55000; j+=i){
        table[j]=1;
      }
    }
  }

  int n;
  while(cin >> 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 <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
    vector<int> primes;
    vector<int> is_prime(50001, 1);
    is_prime[0] = is_prime[1] = 0;
    int lim = (int)sqrt(50000);
    for(int i = 2; i <= lim; ++i) {
        if(is_prime[i]) {
            if(i < lim) {
                for(int j = i*i; j <= 50000; j += i) is_prime[j] = 0;
            }
        }
    }
    for(int i = 2; i <= 50000; ++i) 
        if(is_prime[i]) primes.push_back(i);

    int n;
    while(cin >> n) {
        cout << *(lower_bound(primes.begin(), primes.end(), n)-1) << ' ' << *upper_bound(primes.begin(), primes.end(), n) << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define MAX 100000
int main( void )
{
	vector <bool> primes( MAX+1, false );
	for ( int i = 3; i <= MAX; i += 2 )
		primes[i] = true;

	for ( int i = 3; i <= MAX; i+=2 )
	{
		if ( primes[i] )
		{
			for ( int j = i + i; j <= MAX; j += i )
			{
				primes[j] = false;
			}
		}
	}

	int n;
	while ( cin >> n )
	{
		int max = 0, min = 0;
		int p = n + 2;
		while( !min )
		{
			if ( primes[p] )
				min = p;
			else
				p += 2;
		}

		p = n%2?n:n-1;
		p -= n%2?0:2;
		while( !max )
		{
			if ( primes[p] )
				max = p;
			else
				p -= 2;
		}

		cout << max << " " << min << endl;
	}

}