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>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll; 
typedef pair<ll, ll> PL;

ll  n, b, c;
bool a[1000100];

int main(){
	REP(i, 1000100){
		a[i] = 1;
	}
	a[0] = 0;
	a[1] = 0;
	for (int i = 2; i <= 100000; i++){
		if (a[i]){
			for (int j = 0; i * (j + 2) < 1000000; j++){
				a[i *(j + 2)] = 0;
			}
		}
	}
	while (cin >> n){
		for (int i = n - 1; i > 0; i--){
			if (a[i] == 1){
				cout << i << " ";
				break;
			}
		}
		for (int i = n + 1; i < 100000; i++){
			if (a[i] == 1){
				cout << i << endl;
				break;
			}
		}
	}
}

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

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

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

int primemax(int m) {
	int result = 0;
		while (true) {
		for (int i = m; ; i--) {
			for (int j = i;j>0; j--) {
				if ((i%j)==0)break;
				if (j == 2) { result = i; return result; }
			}
		}
	}
}


int primemin(int m) {
	int result = 0;
		while (1) {
			for (int i = m; ; i++) {
				for (int j = i;j>0 ; j--) {
					if ((i%j)==0)break;
					if (j == 2) { result = i; return result; }
				}
			}
		}
}

C++: #include <bits/stdc++.h>

using namespace std;

int main(){
  int n;
  //cin>>n;

  while(cin>>n){
    int ans_ma;
    int ma_n = n + 1;
    int c_ma = 0;

    if(ma_n % 2 == 0){
        ++ma_n;
    }

    for(int i = ma_n; ;i = i + 2){
      int q = sqrt(i);

      if(q < 3){
        ans_ma = q;
        break;
      }
        
      else{
        c_ma = 1;
        for(int j = 3;j <= q;j = j + 2){
          if(i % j == 0){
            c_ma = 0;
            break;
          }
        }
        if(c_ma == 1){
          ans_ma = i;
          break;
        }
      }
    }

    int ans_mi;
    int mi_n = n - 1;
    int c_mi = 0;

    if(mi_n == 2){
      ans_mi = 2;
    }
    else{
      if(mi_n % 2 == 0){
        --mi_n;
      }
      for(int i = mi_n;i > 3;i = i - 2){
        int q = sqrt(i);

        if(q < 3){
          ans_mi = q;
          break;
        }
        else{
          c_mi = 1;
          for(int j = 3;j <= q;j = j + 2){
            if(i % j == 0){
              c_mi = 0;
              break;
            }
          }
          if(c_mi == 1){
            ans_mi = i;
            break;
          }
        }
      }
    }
    cout<<ans_mi<<" "<<ans_ma<<endl;
  }
  return 0;
}

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

int main(){
  bool is_prime[100000];

  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<100000;i++){
    is_prime[i] = true;
  }

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

  while(true){
    int n;
    cin >> n;

    int a,b;
    int cnt=0;
    for(int i=3;i<=n;i++){
      if(is_prime[i]){
        a=i;
        for(int j=3;j<=n;j++){
          if(is_prime[j]){
            b=j;
            if(a+b==n){
              cnt++;
            }
          }
        }
      }
    }
    if(n==0)
        break;

    cout << cnt/2+1 << endl;
  }

  return 0;
}

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

#define Max 51000
int n;
bool IsPrime[51000];

int main()
{
	for (int i = 2; i < Max; i++) IsPrime[i] = true;

	for (int i = 2; i < Max; i++)
	{
		if (!IsPrime[i]) continue;
		for (int j = i + i; j < Max; j += i) IsPrime[j] = false;
	}

	while (cin >> n)
	{
		for (int i = n - 1; true; i--)
		{
			if (IsPrime[i])
			{
				cout << i << ' ';
				break;
			}
		}

		for (int i = n + 1; true; i++)
		{
			if (IsPrime[i])
			{
				cout << i << endl;
				break;
			}
		}
	}

	return 0;
}

C++: #include<iostream>
#include<vector>
#define MAX 100000
using namespace std;
int main(){
    vector<bool> v(MAX);
    for(int i = 0;i<MAX;i++)
      v[i]=true;

      v[0]=v[1]=false;
    for(int i = 2;i<1000;i++){
      if(v[i]){
        for(int j=i*i;j<MAX;j+=i){
         v[j]=false;
       }
      }
    }
    while(true){
      int a;
      cin >> a;
      if(cin.eof())return 0;
      for(int i = a-1;true;i--){
        if(v[i]){
          cout << i <<' ';
          break;
      }
    }
    for(int i = a+1;true;i++){
      if(v[i]){
        cout <<i<<endl;
        break;
     }
   }
 }
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

int main (int argc, char *argv[]) {
    const int NUM = 50001;
    vector<bool> prime(NUM, true);
    prime[1] = false;
    for (int i = 2; i < NUM; ++i) {
        if (prime[i]) {
            for (int j = i + i; j < NUM; j+=i) {
                prime[j] = false;
            }
        }
    }
    int n, u, d;
    while (cin>>n) {
        for (int i = n-1; i > 1; --i) {
            if (prime[i]) {
                d = i;
                break;
            }
        }
        for (int i = n + 1; i < NUM; ++i) {
            if (prime[i]) {
                u = i;
                break;
            }
        }
        cout << d << " " << u << endl;
    }
    return 0;
}

C++: from itertools import takewhile, dropwhile
pn, tmp = [], [i for i in range(2, 50000)]
while tmp[0] < 224:
    v = tmp.pop(0)
    pn.append(v)
    tmp = list(filter(lambda x: x%v!=0, tmp))
for t in tmp: pn.append(t)
while True:
    try:
        n = int(input())
    except:
        break
    print(list(takewhile(lambda x: x<n, pn))[-1], list(dropwhile(lambda x: x<=n, pn))[0])

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;


int main(){
	char buf[32];
	vector<int> nums;
	map<int,int> freq;
	int* dp = new int[50001];

	fill((int*)dp,(int*)dp+50001,1);

	dp[0]=0;
	dp[1]=0;

	for(int i=0;i<=50000;i++){
		if(dp[i]==1){
			for(int j=i+i;j<=50000;j+=i){
				dp[j]=0;
			}
		}
	}

	int num;
	while(~scanf("%d",&num)){
		for(int i=num-1;i>=0;i--){
			if(dp[i]){
				cout << i << " ";
				break;
			}
		}

		for(int i=num+1;i<=50000;i++){
			if(dp[i]){
				cout << i << endl;
				break;
			}
		}
	}
}

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

int isprime[50101];

int main() {
  memset(isprime, 0, sizeof(isprime));
  for(int i=4; i<50101; i+=2) isprime[i] = 1;
  isprime[1] = 1;
  for(int i=3; i*i<50101; i+=2)
    if(isprime[i] == 0)
      for(int j=2; i*j<50101; ++j)
	isprime[i*j] = 1;

  int n;
  while(cin>>n) {
    for(int k=n-1; k>0; --k)
      if(isprime[k] == 0) {
	cout<<k<<" ";
	break;
      }

    for(int k=n+1; k<50101; ++k)
      if(isprime[k] == 0) {
	cout<<k<<endl;
	break;
      }
  }
}