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 <list>
#include <algorithm>
#include <string>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <complex>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

bool sieve[100010];
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(3);

    for (int i = 0; i < 100010; ++i)
        sieve[i] = true;

    sieve[0] = sieve[1] = false;

    for (int i = 2; i * i < 100010; ++i)
    {
        if (sieve[i])
        {
            for (int j = 2; i * j < 100010; ++j)
            {
                sieve[i * j] = false;
            }
        }
    }
    int n;
    while (cin >> n)
    {
        for (int i = n - 1; i >= 0; --i)
        {
            if (sieve[i])
            {
                cout << i << " ";
                break;
            }
        }
        for (int i = n + 1; i < 100010; ++i)
        {
            if (sieve[i])
            {
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}

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

int main(){
    int n;
    const int N = 1e6;

    vector<bool> is_prime(N,true);
    is_prime[0] = false;
    is_prime[1] = false;

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

    while(cin >> n){
        int small = n-1;
        int big = n + 1;
        while(!is_prime[small]) small--;
        while(!is_prime[big]) big++;

        cout << small << " " << big << endl;
    }


}

C++: #include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define MAX 1000000

using namespace std;

int prime[MAX];

int main()
{
	prime[0] = prime[1] = 0;

	REP(i,2,MAX)
	{
		prime[i] = 1;
	}

	REP(i,2,MAX)
	{
		if(prime[i])
		{
			for(int j = 2;(j*i) <  MAX;j++)
			{
				prime[j*i] = 0;
			}
		}
	}

	int n;

	while(cin >> n)
	{
		for(int i= n-1;i > 0;i--)
		{
			if(prime[i] == 1) 
			{
				cout << i << " ";
				break;
			}
		}
		for(int i = n+1; i < 50001;i++)
		{
			if(prime[i] == 1) 
			{
				cout << i << endl;
				break;
			}
		}
	}


	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

int main(void){
    const int N = (int)1e6;
    bool num[N];
    rep(i, N) num[i] = true;
    for(int i = 2; i * i < N; i ++) if(num[i]) for(int j = i; i * j < N; j ++) num[i * j] = false;

    for(int n; cin >> n;){
        int m = n; while(!num[-- m]); cout << m << " ";
        m = n; while(!num[++ m]); cout << m << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <cstring>
using namespace std;
int main(){
	int n,m;
	bool f[50001];
	memset(f,true,sizeof(f));
	for(int i=2;i<50001;i++){
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				f[i]=false;
				break;
			}
		}
	}
	while(cin>>n){
		for(int i=n-1;;i--){
			if(f[i]){
				cout<<i<<" ";
				break;
			}
		}
		for(int i=n+1;;i++){
			if(f[i]){
				cout<<i;
				break;
			}
		}
		cout<<endl;
	}
	return 0;
}

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

int prime[MAX];

void is_prime(){
  for(int i = 0 ; i < MAX ; i++) prime[i] = i;
  
  prime[0] = prime[1] = 0;
  for(int i = 2 ; i*i < MAX ; i++){
    if(prime[i] = i){
      for(int j = 2*i ; j < MAX ; j += i){
        prime[j] = 0;
      }
    }
  }
}

int main(void){
  int n;

  is_prime();

  while(cin >> n){
    int j=1,k=1,min=0,max=0,flg1=0,flg2=0;
    for(int i = 0 ; i < MAX ; i++){
      if(prime[i] == n){
        while(min==0&&max==0){
          if(flg1 == 0){
            if(prime[i+j]!=0){
	      max = prime[i+j];
              flg1 = 1;
 	    }
          }
          if(flg2 == 0){
            if(prime[i-k]!=0){          
              min = prime[i-k];           
              flg2 = 1;
            }
          }
          j++; k++;     
        }  
      }
      if(max != 0 && min != 0) break;
    }
    cout << min << ' ' << max << endl;
  }

  return 0;
}

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

int main(){
  int n;
  while(cin >> n,n){
    for(int i=n-1; i>0; --i){
      bool frg = true;
      for(int j=2; j*j<i; ++j){
        if(i%j==0){frg=false; break;}
      }
      if(frg){cout << i;break;}
    }
    
    cout << " ";
    
    for(int i=n+1; i<2*n ; ++i){
      bool frg = true;
      for(int j=2; j*j<i; ++j){
        if(i%j==0){frg=false; break;}
      }
      if(frg){cout << i << endl;break;}
    }
    
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#define loop(i,b,n) for(int i = b; i<n; i++)
#define rep(i,n)  loop(i,0,n)
#define INF 10000
#define  MAX 1e7
using namespace std;

int main (){
    vector<bool>check(MAX+1);
    rep(i, MAX+1)
    check[i] = true;
    vector<int>Primenumber(MAX+1,0); //Primearray
    int counter =0;                  //Primearray counter;
    for(int i = 2; i<MAX+1;i++){
        if(check[i]){
            for(int j = 2;i*j<MAX;j++)
                check[i*j] = false;//?´???°??????Primearray???????´??????????????????°?????¨???false???
            Primenumber[counter] = i;
            counter++;
        }
    }
    int n; while(cin >> n){
    int bigans = 0,sans= 0;
    for(int i = n+1 ;n<MAX;i++)
        if(check[i]){bigans = i; break;}
    for(int i = n-1; i>1;i--)if(check[i]){sans = i; break;}
        cout << sans << " " << bigans<< endl;  }  return 0;
}

C++: #include <stdio.h>
#include <math.h>

int isprime(int);

int main(){
	int n,i;
	while(scanf("%d",&n) != EOF){
		for(i = 1;;i++) if(isprime(n - i)) {
			printf("%d ",n - i);
			break;
		}
		for(i = 1;;i++) if(isprime(n + i)) {
			printf("%d\n",n + i);
			break;
		}
	}
	return 0;
}

int isprime(int num){
	int i;
	for(i = 2;i <= (int)sqrt((double)num);i++){
		if(num % i == 0) return 0;
	}
	return 1;
}

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

int sosuu(int i){
  if(i==1)return 0;
  else if(i==2)return 1;
  else if(i%2==0)return 0;
  for(int j=3;j*j<=i;j+=2){
    if(i%j==0)return 0;
  }
  return 1;
}

int main(){
  vector<int>::iterator p;
  vector<int> ve;
  int i=0,k,n;
  while(k<=50000){
    i++;
    if(sosuu(i)){
      k=i;
      ve.push_back(i);
    }
  }
  while(cin>>n){
    p=lower_bound(ve.begin(),ve.end(),n);
    if(*p==n)cout<<*(p-1)<<" "<<*(p+1)<<endl;
    else cout<<*p<<" "<<*(p+1)<<endl;
  }
return 0;
}