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 <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>

#define PI 3.14159265359

#define INF 1000000;

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

typedef long long ll;

using namespace std;


/*
class ElectronicPetEasy
{
public:
	string isDifficult(int st1, int p1, int t1, int st2, int p2, int t2)
	{
		
	}
};
*/


int prime[50000];
bool is_prime[50001];


void sieve(void)
{
	int p = 0;
	
	REP(50001) is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for (int i=2; i<=50000; i++)
	{
		if (is_prime[i])
		{
			prime[p++] = i;
			for (int j=2*i; j<=50000; j+=i) is_prime[j] = false;
		}
	}
}


int main()
{
	int n, less, more;
	
	sieve();
	
	while (cin >> n)
	{
		less = 2;
		for (int i=0; i<50000; i++)
		{
			if (prime[i] > n)
			{
				more = prime[i];
				break;
			} else {
				less = prime[i];
				if (less == n) less = prime[i - 1];
			}
		}
		
		cout << less << " " << more << endl;
	}
	
	return 0;
}

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

bool prime[MAX];
void calcPrime(){
	for(int i = 2; i < MAX; i++) prime[i] = true;
	for(int i = 2; i < MAX; i++){
		if( prime[i] ){
			for(int j = i+i; j <= MAX; j += i){
				prime[j] = false;
			}
		}
	}
}

int main(){
	int n;
	calcPrime();
	while( cin >> n ){
		int under = -1, over = -1;
		for(int d = n-1, u = n+1; ; ){
			if( 2 < d ) d--;
			if( u < MAX ) u++;
			if( under != -1 && over != -1 ) break;
			if( prime[d] ) under = d;
			if( prime[u] ) over = u;
		}
		cout << under << " " << over << endl;
	}
}

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

int primemax(int m);
int primemin(int m);

int main() {
	int n;
	while (scanf_s("%d",&n) != EOF) {
		cout << primemax(n - 1) << " " << primemin(n + 1) << endl;
	}
}

int primemax(int n)
{
	int t;
	for (n;; n--)
	{
		for (t = 2; t <= n; t++)
		{
			if (t == n)
			{
				return n;
			}
			else if (n%t == 0)
			{
				break;
			}
		}
	}
}
int primemin(int n)
{
	int t;
	for (n;; n++)
	{
		for (t = 2; t <= n; t++)
		{
			if (t == n)
			{
				return t;
			}
			else if (n%t == 0)
			{
				break;
			}
		}
	}
}

C++: #include<iostream>
using namespace std;
int main(){
long i,j,k,n;
while(cin>>n){
if(n/2*2==n)k=1;else k=2;
for(j=n-k;j>=3;j-=2){
for(i=3;i*i<n;i+=2)if(j%i==0)break;
if(i*i>=n){cout<<j;break;}
}
if(j==1)cout<<"2";

for(j=n+k;;j+=2){
for(i=3;i*i<n;i+=2)if(j%i==0)break;
if(i*i>=n){cout<<" "<<j<<endl;break;}
}

}
return 0;
}

C++: #include <iostream>
#define x 51000
using namespace std;
int main(){
	bool p[x];
	for(int i=2;i<x;i++) p[i] = true;
	for(int i=2;i<x;i++){
		if(not p[i]) continue;
		for(int j=2;j<=x/i;j++) p[i*j] = false;
	}
	int n;
	while(cin >> n){
		for(int i=n-1;i>1;i--){
			if(not p[i]) continue;
			cout << i << " ";
			break;
		}
		for(int i=n+1;i<x;i++){
			if(not p[i]) continue;
			cout << i << endl;
			break;
		}
	}
}

C++: #include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

bool table[50101];
vector<int> primes;

int main() {
  table[2] = true;
  for (int i = 3; i <= 50100; i += 2)
    table[i] = true;
  for (int i = 3; i <= 224; i += 2)
    if (table[i])
      for (int j = 3 * i; j <= 50100; j += 2 * i)
        table[j] = false;
  primes.push_back(2);
  for (int i = 3; i <= 50100; i += 2)
    if (table[i])
      primes.push_back(i);
  int n;
  while (scanf("%d", &n) == 1) {
    int i = lower_bound(primes.begin(), primes.end(), n)-primes.begin();
    printf("%d %d\n", primes[i-1], primes[i] == n ? primes[i+1] : primes[i]);
  }
  return 0;
}

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

int main(){
  bool  prime[100000];
  for(int i=0;i<100000;i++){
    prime[i]=true;
  }
  prime[0]=prime[1]=false;
  for(int i=2;i<1000;i++){
    for(int j=i*2;j*i<60000;j+=i){
      prime[j]=false;
    }
  }
  int n;
  int cnt1,cnt2;
  while(cin>>n){
    for(int i=0;i<n;i++){
      if(prime[i])cnt1=i;
    }
    for(int i=n+1;;i++){
      if(prime[i]){
	cnt2=i;
	break;
      }
    }
    cout<<cnt1<<" "<<cnt2<<endl;
  }
  return 0;
}

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

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

int main(){
	int n;
	while(cin >> n){
		for(int i = n - 1; i >= 2; i--){
			if(is_sosu(i)) {
				cout << i << " ";
				break;
			}
		}
		for(int j = n+1;;j++){
			if(is_sosu(j)){
				cout << j << 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(max)) break;
     cout<<min<<" "<<max<<endl;            
   }
   //while(1);
   return 0;
 }

C++: #include<iostream>
#include<cmath>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;

const int M = 50000;
bool prime[M];

void isPrime(){
    fill(prime, prime + M, true);
    prime[0] = prime[1] = false;
  
    for(int i = 2; i < M; i++) {
        if(prime[i])
        for(int j = 2; i*j < M ; j++) {
            prime[i*j] = false;
        }
    }
}
int main(void){
  isPrime();
  int n;
  while(cin>>n){
    long long int i = n - 1;
    while(!prime[i])i--;
    cout<<i<<" ";
    i = n + 1;
    while(!prime[++i]);
    cout<<i<<endl;
  }
  return 0;
}

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

using namespace std;

int main(){

  int putin;
  int n;
  int i,j;
  int tap;
  int number[50001];

  for(i=0; i<50001; i++){
    number[i] = 1;
  }

  number[0]=0;
  number[1]=0;
  number[2]=0;

  for(i=2; i<=50000; i++){
    for(j=2; j<=50000; j++){
      tap=i*j;
      if(tap>=50000){
	break;
      } else {
	number[tap] = {0};
      }
    }
  }

  cin >> putin;

  for(n=putin-1; n>0; n--){
    if(number[n]!=0){
      cout << n << " ";
      break;
    }
  }

  for(n=putin+1; n<50000; n++){
    if(number[n]!=0){
      cout << n << endl;
      break;
    }
  } 
}