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 <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

void tamesiwari(int *table, int n){
	table[1] = 1;
	table[2] = 2;
	int count = 3;
	for(int i = 3; i < n; i += 2){
		bool ok = true;
		for(int j = 3; i >= (j * j); j += 2){
			if(i % j == 0) ok = false;
		}
		if(ok) table[count++] = i;
	}
}

int main(){
	int table[60000] = {0};
	tamesiwari(table, 60000);
	int n = 0;
	while(cin >> n){
		if(cin.eof()) break;
		
		for(int i = 0; i < 60000; i++){
			if(table[i] == n){
				cout << table[i - 1] << " " << table[i + 1] << endl;
				break;
			}
		}
	}

	return 0;
}

C++:  
 #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 bool is_prime(int x)
 {
   for(int i=2;i<=(int)sqrt(x);i++)
   {
     if(x%i==0) return false;        
   }     
   return true;
 }
 
 int main()
 {
   int N;
   while(cin>>N)
   {
     int min=N;
     int max=N;
     while(min--) if(is_prime(min)) break;   
     while(max--) if(is_prime(min)) break;
     cout<<min<<" "<<max<<endl;            
   }
   //while(1);
   return 0;
 }

C++: #include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
set<int> primes={5,7,11,13,17,19,23,29,31,37,
                 41,43,47,53,59,61,67,71,73,79,
                 83,89,97,101,103,107,109,113,127,131,
                 137,139,149,151,157,163,167,173,179,181,
                 191,193,197,199,211,223,227};
bool isPrime(int n){
  for(int p:primes){
    if(p*p>n)return true;
    if(n%p==0)return false;
  }
  return true;
}
int main(){
  for(int i=229;i<50040;i+=2)
    if(isPrime(i))
      primes.insert(i);
  int n;
  while(cin>>n){
    auto r=primes.lower_bound(n);
    auto l=r;
    if(primes.count(n)==1){
      r++;l--;
    }
    else{
      l--;l--;
    }
    cout<<(*l)<<" "<<(*r)<<endl;
  }
}

C++: #include<iostream>
using namespace std;
int isPrime[50001];
void prime(){
  for(int i=0;i<50001;i++)isPrime[i]=1;
  isPrime[0]=isPrime[1]=0;
  for(int i=4;i<50001;i+=2)isPrime[i]=0;
  for(int i=3;i*i<=50001;i++){
    if(isPrime[i]){
      for(int j=i+i;j<50001;j+=i)isPrime[j]=0;
    }
  }
}

int main(){
  int a;
  prime();
  while(cin>>a){
    for(int i=a-1;i>=2;i--){
      if(isPrime[i]){
	cout<<i<<' ';
	break;
      }
    }
    for(int i=a+1;i<=50000;i++){
      if(isPrime[i]){
	cout<<i<<endl;
	break;
      }
    }
  }
  return 0;
}

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

C++: #include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;
bool isPrime(int num);

int main(){
	int n;
	while(cin >> n, n){
		int prev = 0;
		int next = 0;
		for(int i = 2; (n-i) >= 3 && (n+i) <= 50000; i += 2){
			if(isPrime(n-i) && prev == 0)
				prev = n-i;
			if(isPrime(n+i) && next == 0)
				next = n+i;
			
			if(prev != 0 && next != 0)
				break;
		}
		cout << prev << " " << next << endl;
	}
	return 0;
}

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

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

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

int main() {
    int n, sp, lp;
    while (cin >> n) {
        for (int i=n-1; i>=2; --i) {
            if (isPrime(i)) {
                sp = i;
                break;
            }
        }
        for (int i=n+1; i<=50021; ++i) {
            if (isPrime(i)) {
                lp = i;
                break;
            }
        }
        cout << sp << " " << lp << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <set>
using namespace std;
bool p[50100];
int main()
{
  int i,j;
  set<int> s;
  s.insert(2);
  for(i=3;i<50100;i+=2){
    if(!p[i]){
      s.insert(i);
      for(j=i*2;j<50100;j+=i){
	p[j] = true;
      }
    }
  }
  while(cin >> i,i){
    set<int>::iterator it = s.upper_bound(i);
    j = *it;
    while(*it >= i) it--;
    cout << *it << " " << j << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <bitset>
#include <cmath>

int main()
{
	const int max = 50021;
	std::bitset<max + 1> bitTable;
	
	bitTable.set(0);
	bitTable.set(1);
	
	int loop = sqrt(max);
	
	for (int i = 2; i <= loop; ++i) {
		if (bitTable.test(i) == false) {
			for (int j = i * i; j <= max; j += i) {
				bitTable.set(j);
			}
		}
	}
	
	int n;
	while (std::cin >> n) {
		int high = n, low = n;
		
		while (bitTable.test(--low));
		while (bitTable.test(++high));
		
		std::cout << low << " " << high << std::endl;
	}
	
	return 0;
}

C++: #include <iostream>
using namespace std;
bool num[50000];
int main()
{
	int n;
	while(cin >> n)
	{
		num[0]=num[1]=true; for(int i=2;i<=n;i++) num[i]=false;
		int ansup,anslow;
		for(int i=2; ;i++)
		{
			if(num[i]==false)
			{
				for(int j=i*2;j<=50000;j+=i) num[j]=true;
			}
			if(i>n && num[i]==false) break;
		}
		for(int j=n+1; ;j++) if(num[j]==false) {ansup=j; break;}
		for(int j=n-1; ;j--) if(num[j]==false) {anslow=j; break;}
		cout << anslow << ' ' << ansup << '\n' ;
	}
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
//#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

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

int p[50005];

int main(){
  loop(i,1,50001)if(Is_Prime(i))p[i]=1;
  int n;
  while(cin>>n){
    for(int i=n-1;;i--){
      if(p[i]){
        cout<<i<<' ';
        break;
      }
    }
    for(int i=n+1;;i++){
      if(p[i]){
        cout<<i<<endl;
        break;
      }
    }
  }
  return 0;
}