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>

using namespace std;

int main(){

  const int NUM = 50100;
  bool prime[NUM];
  prime[0] = false;
  prime[1] = false;
  for(int i=2;i<NUM;i++)
    prime[i] = true;
  for(int i=2;i*i<NUM;i++)
    for(int k=2;i*k<NUM;k++)
      prime[i*k]=false;

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

}

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

using namespace std;

#define MAX 100000

int main(){

    vector<bool> pr(MAX,true);
    vector<int> prime;
    for(int i = 2; i < MAX; i++)if(pr[i]){
        prime.push_back(i);
        for(int j = 2; i*j < MAX; j++)pr[i*j] = false;
    }
    int n;
    while(cin >> n){
        int ans = lower_bound(prime.begin(),prime.end(),n) - prime.begin()-1;
        if(prime[ans+1] == n)
            cout << prime[ans] << " " << prime[ans+2] << endl;
        else
            cout << prime[ans] << " " << prime[ans+1] << endl;
    }
}

C++: #include <iostream>
#include<string>
using namespace std;
int main(){
bool prime[60000];
for(int i=0;i<60000;i++){
prime[i]=1;
}
prime[0]=prime[1]=0;
for(int i=0;i*i<60000;i++){
if(prime[i]==1){
for(int j=i*2;j<60000;j+=i){
prime[j]=0;
}
}
}
int n;
while(cin>>n){
int i;
for(i=1;prime[n-i]==0;i++);
cout<<n-i<<" ";
for(i=1;prime[n+i]==0;i++);
cout<<n+i<<endl;
}
}

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

int main()
{
    int prime[30000];
        prime[0] = 2;
    int num = 1, n;

    for(int i=3; i<50000; i++){
        bool f = true;
        for(int j=0; j<num; j++){
            if(i%prime[j] == 0){
                f = false;
                break;
            }
        }
        if(f){
            prime[num] = i;
            num++;
        }
    }

    while(cin >> n, !cin.eof()){

        int i;

        for(i=0; prime[i]<n; i++){
        }
        cout << prime[i-1] << ' ' << ((prime[i] == n) ? prime[i+1] : prime[i]) << endl;
    }

    return 0;
}

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

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

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

int main() {

int a[50100];
a[0]=0;
a[1]=0;
a[2]=1;
a[3]=1;
a[5]=1;
for(int kk=2;kk<25050;kk++){
	a[2*kk]==0;
}
for(int k=3;k<25050;k++){
	int n,q=1;
	n=sqrt(2*k+1);
	for(int j=1;j<=n/2;j++){
	if(	(2*k+1)%(2*j+1)==0){
		q=0;
	}
	}
a[2*k+1]=q;
}
int p;
while(cin>>p){
	int l=1,m=1;
	while(a[p+l]==0){
		l=l+1;
	}
	while(a[p-m]==0){
		m=m+1;
	}
	cout<<p-m<<" "<<p+l<<endl;
}

	return 0;
}

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

#define MN 60000

int main()
{
	bool pr[MN] = {0};
	for(int i=2; i<MN; i++) pr[i]=1;
	
	for(int i=2; i*i<MN; i++)
	{
		if(pr[i])
		for(int j=i*2; j<MN; j+=i)
		{
			pr[j]=0;
		}
	}

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

C++: #include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int prime[51000]; //i盤目の素数
bool is_prime[51001]; //is_prime[i]がtrueならiは素数

void sieve(int n){ //n以下の素数を返す
	int p=0;
	for(int i=0;i<=n;i++) is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=n;i++){
		if(is_prime[i]){
			prime[p++]=i;
			for(int j=2*i;j<=n;j+=i) is_prime[j]=false;
		}
	}
}

int main(){
	sieve(51000);
	int n;
	while(cin>>n){
		int pre,after;
		rer(i,1,51000){
			if(i<n && is_prime[i]) pre=i;
			if(i>n && is_prime[i]){
				after=i; break;
			}
		}
		o(pre<<" "<<after);
	}
}

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

using namespace std;

int main(void){
  int prime[50000];
  int prime_f[50001];
  int k;
  int n;
  int i,j;
  int n_size;
  bool once;

  while(cin>>n){
    once=true;
    k=0;
    memset(prime_f,0,sizeof(prime_f));
    prime_f[0]=prime_f[1]=1;
    for(i=2;i<50000;i++){
      if(!prime_f[i]){
	k++;
	prime[k]=i;
	if(prime[k]>n&&once){
	  n_size=k-1;
	  once=false;
	}
	for(j=2*i;j<50000;j+=i){
	  prime_f[j]=1;
	}
      }
    }
    cout<<prime[n_size-1]<<" "<<prime[n_size+1]<<endl;
  }  
  return(0);
}

C++: #include<cstdio>

using namespace std;

bool prime[100001];

void prime_checker(){
	for(int i = 3; i < 100000; i+=2){
		if(prime[i]){
			for(int j = i*2; j < 100000; j+=i){
				prime[j] = false;
			}
		}
	}
}

int main(void){
	
	int n;
	
	for(int i = 3; i < 100001; i+=2){
		prime[i] = true;
	}
	prime[0] = false;
	prime[1] = false;
	prime[2] = true;
	
	prime_checker();
	
	while(scanf("%d", &n) != EOF){
		
		for(int i = n-1; i >= 0; i--){
			if(prime[i]){
				printf("%d ",i);
				break;
			}
		}
		for(int i = n+1 ;; i++){
			if(prime[i]){
				printf("%d\n",i);
				break;
			}
		}
	}
	
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
using namespace std;

int main() {

    vector<bool> primes(50030);

    for(int i = 0; i < 50030; i++) {
        primes[i] = true;
    }
    primes[0] = false;
    primes[1] = false;

    for(int i = 2; i < 50030; i++) {
        if (primes[i]) {
            for(int k = 2 * i; k < 50030; k+=i) {
                primes[k] = false;
            }
        }
    }

    int n;
    while(cin >> n) {
        for (int i = n - 1; i >= 2; i--) {
            if (primes[i]) {
                cout << i << " ";
                break;
            }
        }

        for (int i = n + 1; i < 50030; i++) {
            if (primes[i]) {
                cout << i << endl;
                break;
            }
        }
    }
     
    return 0;
}

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(){
#define MAX 1000000  
  bool sosu[MAX]={0};
  for(int i=4;i<MAX;i+=2)sosu[i]=true;
  for(int i=3;i<MAX;i+=2){
    if(sosu[i])continue;
    for(int j=3*i;j<MAX;j+=2*i)sosu[j]=true;
  }
  int n;
  while(cin>>n){
    int i;
    for(i=n-1;i>=2;i--)if(sosu[i]==0)break;
    cout<<i;
    for(i=n+1;i<MAX;i++)if(sosu[i]==0)break;
    cout<<" "<<i<<endl;
  }
}