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;

/*テァツエツ?ヲツ閉ーテ・ツ按、テ・ツョツ?/
const int MAX = 1000100;
bool prime[MAX];

void sieve(){
	fill(prime, prime+MAX, true);
	prime[0] = prime[1] = false;

	for(int i=2; i*i < MAX; i++){
		if(!prime[i]) continue;
		for(int j=i*i; j < MAX; j += i) prime[j] = false;
	}
}


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

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

void prime(int a){
  int cnt1=a+1;
  int cnt2=a-1;
  bool is_prime[1000000];
  is_prime[0] = is_prime[1] = false;
  for(int i=2;i<1000000;i++){
    is_prime[i] = true;
  }
  for(int i=2;i*i<1000000;i++){
    if(is_prime[i]){
      for(int j=i*i;j<1000000;j+=i){
        is_prime[j] = false;
      }
    }
  }
  while(1){
    if(is_prime[cnt2]){
      cout << cnt2 << " ";
      break;
    }
    cnt2--;
  }

  while(1){
    if(is_prime[cnt1]){
      cout << cnt1 << endl;
      break;
    }
    cnt1++;
  }

}

int main(){
  while(1){
    int num;
    cin >> num;
    if(cin.eof())
      break;

    prime(num);
  }
  return 0;
}

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

bool prime(int n) {
	switch (n) {
	case 1: return false;
	case 2:
	case 3: return false;
	}
	if (n % 2 == 0 || n % 3 == 0) return false;
	if (n % 6 != 1 && n % 6 != 5) return false;
	for (int j = 5; j * j <= n; j += 6) {
		if (n % j == 0) return false;
		if (n % (j + 2) == 0) return false;
	}
	return true;
}
int main() {
	int n;
	while (cin >> n) {
		int sn = 0;
		int bn = 0;
		for (int i = 1;; i++) {
			if (sn == 0 && prime(n - i)) sn = n - i;
			if (bn == 0 && prime(n + i)) bn = n + i;
			if (sn != 0 && bn != 0) break;
		}
		cout << sn << " " << bn << endl;
	}
	return 0;
}

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

int main()
{
    int n;
    int max,first;
    bool flag=false;
    while(cin>>n,!cin.eof()){
        for(int i=2;i<n;i++){
            for(int j=2;j<i;j++){
                if(i%j==0){
                    break;
                }
                if(i-1==j){
                    max=i;
                }
            }
        }
        cout<<max<<' ';
        bool flag=false;
        for(int i=n+1;;i++){
            for(int j=2;j<i;j++){
                if(i%j==0){
                    break;
                }
                if(i-1==j){
                    first=i;
                    flag=true;
                    break;
                }
            }
            if(flag)break;
        }
        cout<<first<<endl;
    }
    return 0;
}

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

int prime[5144],size;

bool isPrime(int x){
	for(int i=0;i<size && prime[i]<=sqrt(x);i++){
		if(x % prime[i] == 0) return false;
	}
	return true;
}

void mkPrime(void){
	size = 1;
	prime[0] = 2;

	for(int i=3;i<50100;i+=2){
		if(isPrime(i)){
			prime[size++] = i;
		}
	}
}

int main(void){
	int i,x;

	mkPrime();

	while(cin>>x){
		for(i=0;prime[i]<x;i++);

		if(x == prime[i]){
			cout<<prime[i-1]<<" "<<prime[i+1]<<endl;
		}
		else{
			cout<<prime[i-1]<<" "<<prime[i]<<endl;
		}
	}

	return 0;
}

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

bool isPrime(int n) {
  if ( n == 2 ) return true;
  for(int d = 2; d * d <= n; d++)
    if( n % d == 0 ) return false;
  return true;
}

int main() {
  for(int n; cin >> n; ) {
    int small = n;
    int large = n;
    while( !isPrime(--small) );
    while( !isPrime(++large) );
    cout << small << ' ' << large << endl;
  }
  return 0;
}

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

using namespace std;

int main(){

  vector<int> arr(80000);

  for(int i=0;i<80000;++i)
	arr[i] = 1;

  for(int i=2;i<sqrt(80000);++i){
	if(arr[i]){
	  for(int j = 0;i*(j+2) < 80000; j++)
		arr[i*(j+2)] = 0;
	}
  }

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

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

C++: #include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
bool isPrime[50005];

void generate(){
	memset(isPrime,true,sizeof(isPrime));
	isPrime[0] = isPrime[1] = false;
	for(int x=2;x<50005;++x){
		if(isPrime[x]){
			for(int i=x*x;i<50005;i += x){
				isPrime[i] = false;
			}
		}
	}
}

int main(){
	generate();
	int n;
	while(cin>>n){
		int j = n-1;
		while(!isPrime[j]){
			j--;
		}
		cout<<j<<" ";
		j = n+1;
		while(!isPrime[j]){
			j++;
		}
		cout<<j<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

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

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

}

C++: #include<iostream>
#include<list>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 60000
#define PRIME 0

int isprime[MAX];

int main()
{
    //memset(isprime,1,sizeof(isprime));
    isprime[0]=1;
    isprime[1]=1;
    for(int i=2;i<MAX;i++)
    {
        if(isprime[i]==PRIME)
        for(int j=2;j<MAX;j++)
        {
            if(i*j>=MAX) break;
            isprime[i*j] = 1;

        }
    }
    list<int> plist;
    for(int i=2;i<MAX;i++)
    {
        if(isprime[i]==0) plist.push_back(i);
    }
    int n;
    while(cin>>n)
    {
        int a,b;
        list<int>::iterator it = upper_bound(plist.begin(),plist.end(), n);
        b = *it;
        --it;
        if(*it<n) a= *it;
        else{--it;a= *it;}


        cout << a <<" "<< b <<endl;

    }
    
    return 0;
}

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

int main(){
  int table[50001]={};
  for(int i=2; i<1000; ++i){
    if(!table[i]){
      for(int j=i*2; j<=50001; 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;
}

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

int main(){
	bool dt[51001];
	int count=0;
	for(int i=1;i<51001;i++){
		for(int j=1;j<7001;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;
}