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<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    bool prime[50100] = {true, true, false};
    int p[20000], j = 2;
    rep(i,50100){
        if(!prime[i]){
            p[j++] = i;
            for(int j = i + i; j < 50100; j+=i){
                prime[j] = true;
            }
        }
    }

    int n;
    while(cin >> n){
        int i = 2;
        while(true){
            if(p[i] < n && p[i + 1] > n){
                cout << p[i] << ' ' << p[i + 1] << endl;
                break;
            }else if(p[i] == n){
                cout << p[i - 1] << ' ' << p[i + 1] << endl;
                break;
            }else if(p[i + 1] == n){
                cout << p[i] << ' ' << p[i + 2] << endl;
                break;
            }
            i++;
        }
    }
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#define N (60000)
int pt[N];

int main() {
    for (int i = 2; i < N; i++) if (pt[i] == 0) {
        for (int j = i+i; j < N; j+=i) pt[j] = i;
    }
    int n;
    while (scanf("%d", &n) != EOF) {
        int lo = n-1, hi = n+1;
        while (pt[lo]) lo--;
        while (pt[hi]) hi++;
        printf("%d %d\n", lo, hi);
    }
    return 0;
}

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

#include<vector>

#define INF 999999
using namespace std;
bool prime[55000]={0};
int main(){
    prime[1]=1;
    for(int i=2;i*i<55000;i++){
        if(prime[i]==0){
            for(int j=i;j<=55000;j+=i){
                if(prime[j]==0){
                    prime[j]=1;
                }
            }
            prime[i]=0;
        }
    }
    int N;
    while(~scanf("%d",&N)){
        for(int i=N-1;;i--){
            if(prime[i]==0){cout<<i<<" ";break;}
        }
        for(int i=N+1;;i++){
            if(prime[i]==0){cout<<i<<endl;break;}
        }
    }
    return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

bool prime(int p){
	int i;
	for(i=2;i<p;i++){
		if(p%i==0)break;
	}
	return i==p;
}

int main() {
	int n;
	while(cin>>n){
		int p=n-1;
		while(!prime(p))p--;
		cout<<p<<" ";
		p=n+1;
		while(!prime(p))p++;
		cout<<p<<"\n";
	}
	return 0;
}

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

using namespace std;

int main(){

  int putin;
  int n;
  int i,j;
  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<100; i++){
    for(j=2; j<500; j++){
      number[i*j] = {0};
    }
  }

  cin >> putin;

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

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

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

int main(){
	bool dt[51001];
	int count=0;
	for(int i=1;i<50001;i++){
		for(int j=1;j<251;j++){
			if(i%j==0)count++;
		}
		if(count==2){dt[i]=true;}
		else{dt[i]=false;}
		count=0;
	}
	int n=0;
	while(cin>>n){
		int i=0;
		int ansf=0,ansl=0;
		for(i=1;i<n;i++){
			if(dt[i]==true){ansf=i;}
		}
		i++;
		while(i>0){
			if(dt[i]==true){ansl=i;i=-10;}
			i++;
		}
		cout<<ansf<<" "<<ansl<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
bool sosuu(int x){
bool c=true;
int a;
for(int j=2;j*j<=x;j++){
a=x;
a%=j;
if(a==0){c=false; break;}}
if(c)return true;
else return false;}

int main(){
int n;
while(cin>>n){
for(int i=n-1;i>1;i--){
if(sosuu(i)){cout<<i<<" "; break;}}
while(1){
n++;
if(sosuu(n)){cout<<n<<endl; break;}}}}

C++: #include <cstdio>
#define N 50022
#define REP(i, a, b) for (int i = a; i < b; ++i)
bool p[N+1];
int main()
{
	REP(i, 0, N+1) p[i] = true;
	for (int i = 2; i * i <= N; ++i)
		if (p[i]) for (int j = 2 * i; j <= N; j += i)
			if (p[j]) p[j] = false;
	int n;
	while (scanf("%d", &n) == 1) {
		for (int i = n-1; i >= 2; --i) if (p[i]) { printf("%d ", i); break; }
		for (int i = n+1; i <= N; ++i) if (p[i]) { printf("%d\n", i); break; }
	}
	return 0;
}

C++: #include<iostream>

bool sieve[100000];
void makesieve();

int main()
{
	makesieve();
	while(1)
	{
		int n,s,l;
		std::cin>>n;
		if(std::cin.eof())break;
		for(s=n-1;sieve[s]!=true;s--);
		for(l=n+1;sieve[l]!=true;l++);
		std::cout<<s<<' '<<l<<std::endl;
	}
	return 0;
}

void makesieve()
{
	for(int i=0;i<100000;i++){sieve[i]=true;}
	sieve[0]=false;sieve[1]=false;
	for(int i=2;i<100000;i++)
	{
		for(int j=i*2;j<100000;j+=i)
		{
			sieve[j]=false;
		}
	}
}

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, next = 0;
		
		for(int i = n-2; i >= 3; i -= 2){
			if(isPrime(i)){
				prev = i;
				break;
			}
		}
		
		for(int i = n+2; i <= 50000; i += 2){
			if(isPrime(i)){
				next = i;
				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<string>
using namespace std;

int IsPrime(int num){
    if(num < 2){
        return 0;
    }else if(num == 2){
        return 1;
    }else{
        for(int i = 2; i*i <= num;i++){
            if(num % i == 0){
                return 0;
            }
        }
        return 1;
    }
}

int main() {
    std::string str;
    int num = 0;
    std::cin >> num;
    for(int i = num-1; 2 < i;i--){
        if(IsPrime(i) == 1){
            printf("%d ",i);
            break;
        }
    }
    for(int k = num+1;; num++){
        if(IsPrime(k) == 1){
            printf("%d\n",k);
            break;
        }
    }
    
}