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 <stdio.h>
#include <math.h>

#define NUM 1000000

int main(void)
{
  unsigned i, j;
  unsigned sq_num = (int)sqrt((double)NUM);
  unsigned prime[NUM];
  int n, x;

  scanf("%d",&n);

  for (i = 0; i < NUM; i++)
    prime[i] = 1;  
  prime[0] = 0;    

  for (i = 1; i < sq_num; i++) {
    if (prime[i] == 1)          
      for (j = (i+1); (i+1) * j <= NUM; j++)
        prime[(i+1) * j - 1] = 0;  
  }

  for (i = 0; i < NUM; i++){
  	if (prime[i] == 1 && i < n)
  		x = i;

    if (prime[i] == 1 && i > n){
      printf("%d %d\n", x, i + 1);
      break;
    }

}
  return 0;
}

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

const int NUM_MAX = 50000;

bool isPrime(int num){
    for(int i=3; i*i<=num; i+=2){
        if(num%i==0){
            return false;
        }
    }
    return true;
}

int getPrimeOverMin(int value){
	if((value & 0x00000001) == 0x00000000){
		++value;
	}
	for(int i=value+2; i>0; i+=2){
		if(isPrime(i)){
			return i;
		}
	}
	return 0;
}

int getPrimeUnderMax(int value){
	if((value & 0x00000001) == 0x00000000){
		--value;
	}
	if(value==3)return 2;

	for(int i=value-2; i>3; i-=2){
		if(isPrime(i)){
			return i;
		}
	}
	return 0;
}


//0044
int main(){
	int n;
	
	while(cin >> n){
		cout << getPrimeUnderMax(n) << " " << getPrimeOverMin(n) << endl;
	}
	return 0;	
}

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

bool prime(int x){
	if(x==0||x==1) return false;
	for(int i=2;i*i<=x;i++){
		if(x%i==0) return false;
	}
	return true;
}

int main(){
	int n,nl,nh;
	while(cin>>n){
		nl=n;
		nh=n;
		while(nl!=3){
			nl--;
			if(prime(nl))break;
		}
		while(1){
			nh++;
			if(prime(nh))break;
		}
		cout<<nl<<" "<<nh<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>

using namespace std;

typedef pair<int, bool> elem;

int main()
{
    vector<elem> is_prime(50021 + 1);

    is_prime.at(0) = elem(0, false);
    is_prime.at(1) = elem(1, false);

    for (size_t i = 2; i < 50021 + 1; i++) {
        is_prime.at(i) = elem(i, true);
    }

    for (size_t i = 2; i < is_prime.size() / 2; i++) {
        if (is_prime.at(i).second) {
            for (size_t j = i * 2; j < is_prime.size(); j += i) {
                is_prime.at(j).second = false;
            }
        }
    }

    int in;
    while (cin >> in) {
        for (size_t it = in - 1; it != 0; it--) {
            if (is_prime.at(it).second) {
                cout << is_prime.at(it).first << " ";
                break;
            }
        }

        for (size_t it = in + 1; it != is_prime.size(); it++) {
            if (is_prime.at(it).second) {
                cout << is_prime.at(it).first << endl;
                break;
            }
        }
    }

    return 0;
}

C++: #include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
const int PRIME_MAX = 51000;

int main() {
  vector<int> primes(PRIME_MAX);
  iota(primes.begin(), primes.end(), 0);
  primes[0] = primes[1] = -1;
  for (int i = 2; i * i <= PRIME_MAX; i++) {
    if (primes[i] == -1) {
      continue;
    }
    for (int j = (i << 1); j < PRIME_MAX; j += i) {
      primes[j] = -1;
    }
  }
  primes.erase(remove(primes.begin(), primes.end(), -1), primes.end());

  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 <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	deque<bool> is_prime(50022,true);
	is_prime[0]=is_prime[1]=false;
	repi(i,2,is_prime.size()){
		if(!is_prime[i])
			continue;
		for(int j=i+i;j<(int)is_prime.size();j+=i)
			is_prime[j]=false;
	}
	for(int n;cin>>n;){
		for(int i=n-1;;i--){
			if(is_prime[i]){
				cout<<i<<" ";
				break;
			}
		}
		for(int i=n+1;;i++){
			if(is_prime[i]){
				cout<<i<<endl;
				break;
			}
		}
	}
	
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find(all(v), i) != (v).end())
#define ERASE(v,i) (v).erase(remove(all(v), i), (v).end())
#define INDEX(v,i) (find(all(v), i) - (v).begin())
#define rep(i,n) for(int i = 0; i < (int)n; ++i)
#define debug(x) cerr << #x << " = " << (x) << endl;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

const int INF = 100000000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

const int pm = 100000;
bool prime[pm];

int main() {
	fill(prime, prime + pm, true);
	prime[0] = prime[1] = false;
	for(int i = 2; i * i <= pm; i++)
		if(prime[i])
			for(int j = 2 * i; j <= pm; j += i)
				prime[j] = false;
	for(int n; cin >> n;) {
		int more, less;
		for(int i = n - 1; i >= 0; i--) {
			if(prime[i]) {
				less = i;
				break;
			}
		}
		for(int i = n + 1; i <= pm; i++) {
			if(prime[i]) {
				more = i;
				break;
			}
		}
		cout << less << " " << more << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int num[50010],n,ma,anslow=0,anshigh=0;
    ma=sqrt(50010);
    for(int i=2;i<50010;i++)num[i]=0;
    for(int i=2;i<ma;i++){
        if(num[i]==0){
            for(int j=2;j*i<50010;j++)num[j*i]=1;
        }
    }
    while(cin>>n){
        for(int i=1;anslow==0||anshigh==0;i++){
            if(num[n-i]==0&&anslow==0)anslow=n-i;
            if(num[n+i]==0&&anshigh==0)anshigh=n+i;
        }
        cout<<anslow<<" "<<anshigh<<endl;
        anshigh=0;anslow=0;
    }
}