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<cmath>
#define NUM 100000
using namespace std;
int p[NUM];

int main(){
	int i,j;
	p[0]=0;//ツ素ツ青板テツーツブツδ仰づーツ催ャツづゥ
	p[1]=0;
	for(i=2;i<NUM;i++)p[i]=1;
	for(i=2;i<sqrt(NUM);i++){
		if(p[i]){
			for(j=i*2;j<NUM;j+=i){
				p[j]=0;//ツ倍ツ青板づーツ渉慊つュ
			}
		}
	}
	/*
	for(i=0;i<NUM;i++)
		if(p[i])cout<<i<<",";
		*/
	int a;
	int min,max;
	while(cin>>a){
		for(i=a-1;i>=0;i--){
			if(p[i]){
				min=i;
				break;
			}
		}
		for(j=a+1;j<=NUM;j++){
			if(p[j]){
				max=j;
				break;
			}
		}
		cout<<min<<" "<<max<<endl;		
	}
	
	return 0;
}

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


int prime[60000];


void sieve(){
	memset(prime, 1, sizeof prime);
	int i;
	for(i = 2;i*i <= 60000;i++){
		if(prime[i]){
			for(int j = 2;i*j <= 60000;j++){
				prime[i*j] = 0;
			}
		}
	}
}


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

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

using namespace std;

int main(){

	int data[50100+1];
	int state=0;
	//素数表の作成
	for(int i=1;i<=50100;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;
bool flag[60000];
int main()
{
	flag[0]=flag[1]=true;

	for(int i=2;i<60000;i++)
	{
		if(!flag[i])
		{
			for(int j=i*2;j<60000;j+=i) flag[j]=true;
		}
	}

	int n,low,up;
	while(cin>>n)
	{
		for(int i=n-1;;i--)
		{
			if(!flag[i]) {low=i; break;}
		}
		for(int i=n+1;;i++)
		{
			if(!flag[i]) {up=i; break;}
		}
	
		cout<<low<<" "<<up<<endl;
	}
	return 0;
}

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

using namespace std;

int main(void) {
    const int N = 100000;
    bool p[N];
    fill(p, p + N, true);
    for (int i = 2; i < N; i++) {
        if (!p[i]) continue;
        for (int j = i * 2; j < N; j += i) {
            p[j] = false;
        }
    }
    int n, a, b;
    while (true) {
        cin >> n;
        if (cin.eof()) break;
        for (a = n - 1; !p[a]; a--);
        for (b = n + 1; !p[b]; b++);
        cout << a << " " << b << endl;
    }
    return 0;
}

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

int main(){
  int n;
  while(cin >> n,n){
    for(int i=n-1;i>0; --i){
      bool frg = true;
      for(int j=2; j*j<i; ++j){
        if(i%2==0){frg=false; break;}
        if(i%j==0){frg=false; break;}
      }
      if(frg){cout << i;break;}
    }
    
    cout << " ";
    
    for(int i=n+1;i<n*n; ++i){
      bool frg = true;
      for(int j=2; j*j<i; ++j){
        if(i%2==0){frg=false; break;}
        if(i%j==0){frg=false; break;}
      }
      if(frg){cout << i << endl;break;}
    }
    
  }
  return 0;
}

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

int n;
int check(int i)
{
    if(i%2==0) return 0;
    for(int a=3;a*a<=i;a+=2)
    {
        if(i%a==0) return 0;
    }
    return 1;
}
int solve_a()
{
    int i;
    for(i=n-1;!check(i);i--);
    return i;
}
int solve_b()
{
    int i;
    for(i=n+1;!check(i);i++);
    return i;
}
int main()
{
    while(cin >> n)
    {
        cout << solve_a() << ' ' << solve_b() << endl;
    }
}

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

int main()
{
	int a[50101]={0};
	int i,j;
	int n,c;

	a[2]=1;
	for(i=3;i<=50100;i+=2){
		if(a[i]==2)
			continue;
		else if(a[i]==0){
			a[i]=1;
			for(j=i*2;j<=50100;j+=i)
				a[j]=2;
		}
	}
	while(scanf("%d",&n)!=EOF){
		for(i=n-1;i>1;i--){
			if(a[i]==1){
				printf("%d ",i);
				break;
			}
		}
		for(i=n+1;i<=50100;i++)
			if(a[i]==1){
				printf("%d\n",i);
				break;
			}
	}
	return 0;
}

C++: #include <cmath>
#include <iostream>

using namespace std;

bool prime_check(int N)
{
	if (N == 1) { 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)
	{
		for (int i = (N - 1); i > 1; i--)
		{
			if (prime_check(i) == true)
			{
				cout << i << ' '; goto Exit1;
			}
		}

	Exit1:;

		for (int i = (N + 1); i <= 50000; i++)
		{
			if (prime_check(i) == true)
			{
				cout << i << endl; goto Exit2;
			}
		}

	Exit2:;
	}

	return 0;
}

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

const int MAX_NUM = 500000;
bool prime_number[MAX_NUM];
 
void isPrime() {
    fill(prime_number, prime_number + MAX_NUM, true);
    prime_number[0] = prime_number[1] = false;
 
    for(int i = 2; i < MAX_NUM; i++) {
        if(prime_number[i])
        for(int j = 2; i*j < MAX_NUM; j++) {
            prime_number[i*j] = false;
        }
    }
}
int main(void){
  int n;
  isPrime();
  while(cin>>n){
    int i;

    for(i = (!prime_number[n]?n:n-1) ; !prime_number[i] ; i --);
    cout<<i<<" ";
    for(i = (!prime_number[n]?n:n+1) ; !prime_number[i] ; i ++);
    cout<<i<<endl;
  }
}

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

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

const int SIZE = 50030;
bool isprime[SIZE + 1] = {0};
vector<int> prime;
void make_prime(){
    isprime[1] = true;
    isprime[0] = true;
    for(int i = 2; i <= SIZE; i++){
        if(isprime[i]) continue;
        for(int j = i * 2; j <= SIZE; j += i) isprime[j] = true;
        prime.push_back(i);
    }
}

int main(){
    make_prime();
    int n;
    while(cin >>n){
        int min, max;
        for(min = n - 1; isprime[min] != false; min--) ;
        for(max = n + 1; isprime[max] != false; max++) ;
        cout <<isprime[50007] <<endl;
        cout <<min <<" " <<max <<endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

const int MAX_NUM =  50000 ;
bool prime_number[MAX_NUM];
 
void prime_create() {
  fill(prime_number, prime_number + MAX_NUM, true);
  prime_number[0] = prime_number[1] = false;
 
  for(int i = 2; i < MAX_NUM; i++) {
    if(prime_number[i])
      for(int j = 2; i*j < MAX_NUM; j++) {
	prime_number[i*j] = false;
      }
  }
}

int main(void){
  prime_create();
  int n;
  while(cin>>n){
    int i;

    for(i = (!prime_number[n]?n:n-1) ; !prime_number[i] ; i --);
    cout<<" "<<i<<" ";
    for(i = (!prime_number[n]?n:n+1) ; !prime_number[i] ; i ++);
    cout<<i<<endl;
  }
}