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 <algorithm>
using namespace std;
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define PP(m) REP(i, m.size()) cout << m[i] << endl;

vector<bool> isPrime;
ll primed = 0;

void eratosu(ll max){
  if (max < primed) return;
  else primed = max;

  if (max+1 > isPrime.size()) {
    isPrime.resize(max+1,true);
  }
  isPrime[0] = false;
  isPrime[1] = false;

  for(ll i = 2; i * i <= max; ++i) {
    if (isPrime[i]) {
      for(ll j = 2; i * j <= max; ++j) {
        isPrime[i*j] = false;
      }
    }
  }
}

int main() {
  int a, b, c;
  eratosu(100000);
  while (cin >> a && a) {
    b=a-1; c=a+1;
    while (!isPrime[b]) b--;
    while (!isPrime[c]) c++;
    cout << b << " " << c << endl;
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	vector<bool>v(50030, true);
	v[0] = v[1] = false;
	rep(i, 2, sqrt(50030)) {
		if (v[i]) {
			for (int j = i + i; j < 50030; j += i) {
				v[j] = false;
			}
		}
	}
	int n;
	while (cin >> n) {
		for (int i = n-1;; i--) {
			if (v[i]) {
				cout << i;
				break;
			}
		}
		for (int i = n + 1;; i++) {
			if (v[i]) {
				cout << " " << i << endl;
				break;
			}
		}
	}
	return 0;
}

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


using namespace std;


vector<int> CreatePrimes(int n)
{
	bool* work = new bool[n+1];

	fill(work, work+(n+1), true);
	work[0] = work[1] = false;

	vector<int> res;
	res.push_back(2);
	for (int i = 4; i <= n; i += 2)
		work[i] = false;

	for (int i = 3; i <= n; i += 2)
	{
		if (work[i])
		{
			res.push_back(i);
			for (int j = 2*i; j <= n; j += i)
				work[j] = false;
		}
	}

	delete[] work;

	return res;
}

int main()
{
	vector<int> primes = CreatePrimes(51000);
	int n;
	while (scanf("%d", &n) != EOF)
	{
		int minP = *(lower_bound(primes.begin(), primes.end(), n) - 1);
		int maxP = *upper_bound(primes.begin(), primes.end(), n);
		printf("%d %d\n", minP, maxP);
	}

	return 0;
}

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

int main(){
    bool isPrime[n_size];
    isPrime[0] = false;
    isPrime[1] = false;

    for (unsigned i = 2; i < n_size; i++)
        isPrime[i] = true;

    for (unsigned i = 2; i * i < n_size; i++){
        if (isPrime[i]){
            for (unsigned j = (i * i); j < n_size; j += i)
                isPrime[j] = false;
        }
    }

    unsigned n;
    while(cin >> n && n!=0){
        unsigned cnt = 0;
        for(unsigned i=n-1;i>=n-i;i--){
            if(n%2!=0)
                break;
            if(isPrime[i] && isPrime[n-i])
                cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}

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

int main() {
	bool prime[100000];
	fill(prime, prime + 100000, 1);
	prime[0] = prime[1] = false;
	for (int i = 2; i * i < 100000; i++) {
		for (int j = 2; i * j < 100000; j++) {
			if (!prime[i * j]) continue;
			prime[i * j] = false;
		}
	}

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

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

bool prime[50030];

int main(){
    memset( prime, 0, sizeof(prime) );
    for( int i=2; i<224; i++ ){
        if( !prime[i] ){
            for( int j=i+i; j<50030; j+=i ){
                prime[j] = true;
            }
        }
    }

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

C++: #include <iostream>
#include <set>
using namespace std;
bool p[50100];
int main()
{
  int i,j;
  set<int> s;
  for(i=2;i<50100;i++){
    if(!p[i]){
      s.insert(i);
      for(j=i*2;j<50100;j+=i){
	p[j] = true;
      }
    }
  }
  while(cin >> i,i){
    set<int>::iterator it = s.upper_bound(i);
    j = *it;
    while(*it >= i) it--;
    cout << *it << " " << j << endl;
  }
  return 0;
}

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

bool IsPrime(int num){
    if(num < 2){
        return false;
    }else if(num == 2){
        return true;
    }else{
        for(int i = 2; i<= sqrt(num);i++){
            if(num % i == 0){
                return false;
            }
        }
        return true;
    }
}

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

}

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

using namespace std;

int main(){

	int data[50000+1];
	int state=0;
	//素数表の作成
	for(int i=1;i<=50000;i++){
		data[i]=0;
		state = 0;
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				state=1;
				break;
			}
		}
		if(state==0){
			data[i]=1;
		}
	}
	int num;

	while(cin>>num){
		int ans0,ans1;

		for(ans0=num-1;;ans0--){
			if(data[ans0]==1){
				break;
			}
		}
		for(ans1 = num+1;;ans1++){
			if(data[ans1]==1){
				break;
			}
		}
		cout<<ans0<<" "<<ans1<<endl;
	}
	return 0;

}

/*
Sample Input
19
3517
Output for the Sample Input
17 23
3511 3527
*/

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

int main(){
  int table[80000]={};
  for(int i=2; i<10000; ++i){
    if(!table[i]){
      for(int j=i*2; j<=80000; j+=i){
        table[j]=1;
      }
    }
  }
  
  int n;
  while(cin >> n,n){
    int i;
    for(i=n-1; table[i]; --i);
    cout << i << " ";
    for(i=n+1; table[i]; ++i);
    cout << i << endl;
  }
  return 0;
}