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<math.h>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
   int prime[50000];
   prime[0] = 2;
   prime[1] = 3;
   int ptr = 2;
   for(int num = 5; num <= 50100; num++){
       bool f = false;
       for(int i=0;i<ptr;i++){
           if(prime[i]*prime[i]>num){
               break;
           }
           if(num%prime[i]==0){
               f=true;
               break;
           }
       }
       if(!f){
           prime[ptr++] = num;
       }
   }
   int n;
   while(cin>>n){
       int j=0;
       while(prime[j]<=n){
           j++;
       }
       if(prime[j-1]==n){
           printf("%d %d",prime[j-2],prime[j]);
       }else{
           printf("%d %d",prime[j-1],prime[j]);
       }
       cout<<endl;
   }
   return 0;
}

C++: #include <iostream>
#include <cstring>
using namespace std;
int main(){
	int n,m;
	bool f[50001];
	memset(f,true,sizeof(f));
	for(int i=2;i<50001;i++){
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				f[i]=false;
				break;
			}
		}
	}
	while(cin>>n){
		for(int i=n-1;;i--){
			if(f[i]){
				cout<<i<<" ";
				break;
			}
		}
		for(int i=n+1;;i++){
			if(f[i]){
				cout<<i;
				break;
			}
		}
		cout<<endl;
	}
	return 0;
}

C++: #include<stdio.h>

int main(){
	int i,no,flag;
	int prime[500];
	int ptr = 0;
	unsigned long counter = 0;
	prime[ptr++]=2;
	prime[ptr++]=3;
	
	for( no = 5 ; no <= 1000 ; no += 2){
		flag = 0;
		for (i = 1; counter++,prime[i] * prime[i] <= no ; i++){
			counter++;
			if(no % prime[i] == 0){
				flag=1;
				break;
			}
		}
		if(!flag)
			prime[ptr++] = no;
	}
	
	for(i = 0 ; i < ptr ; i++){
		printf("%d\n",prime[i]);
	}
	printf("乗除を行った回数%lu\n",counter);

}

C++: #include<iostream>
#include<vector>
#define NUM 100000
using namespace std;
int main(){
  int n, prime[NUM], p[NUM],c=0;
  for(int i=0; i<NUM; i++){
   prime[i] = 0;
   p[i] = 0;
  }
  prime[0] = 1;
  for(int i=2; i<=NUM/2; i++){
      for(int j=2; i*j <= NUM; j++){
	if(prime[i*j-1] == 0)
	  prime[i*j-1] = 1;
      }
  }
  
  for(int i=0; i<NUM; i++){
    if(prime[i] == 0){
      p[c] = i+1;
      c++;
    }
  }

  while(cin >> n){
    if(n < 3 || n > 50000) continue;
    for(int i=0; i<NUM; i++){
      if(n == p[i]){
      	  c=i;
      	  break;
      }
    }
    if(c-1 < 0 || c+1 > NUM) continue;
    else cout << p[c-1] << " " << p[c+1] << endl;
  }
  return 0;
  
}

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

vector<int> get_prime(int n){
    if(n <= 1) return vector<int>();
    vector<bool> is_prime(n+1, true);
    vector<int> prime;
    is_prime[0] = is_prime[1] = 0;
    for (int i = 2; i <= n; ++i) {
        if(is_prime[i]) prime.emplace_back(i);
        for (auto &&j : prime){
            if(i*j > n) break;
            is_prime[i*j] = false;
            if(i % j == 0) break;
        }
    }
    return prime;
}

int main() {
    auto v = get_prime(50100);
    int n;
    while(cin >> n){
        auto p = upper_bound(v.begin(),v.end(), n);
        int ans2 = *p;
        p--; if(*p == n) p--;
        cout << *p << " " << ans2 << "\n";
    }
    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+=i){
				is_prime[j]=false;
			}
		}
	}

	while(true){

		int n;
		cin>>n;

		if(cin.eof()){
			break;
		}

		int tmp = n;
		while(true){
			tmp--;
			if(is_prime[tmp]==true){
				cout << tmp << " ";
				break;
			}
		}
		tmp = n;
		while(true){
			tmp++;
			if(is_prime[tmp]==true){
				cout << tmp << endl;
				break;
			}
		}
	}
	return 0; 
}

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

int main()
{
    int prime[30000];
        prime[0] = 2;
    int num = 1, n;

    for(int i=3; i<50000; i++){
        bool f = true;
        for(int j=0; j<num; j++){
            if(i%prime[j] == 0){
                f = false;
                break;
            }
        }
        if(f){
            prime[num] = i;
            num++;
        }
    }

    while(cin >> n, n){

        int i;

        for(i=0; prime[i]<n; i++){
        }
        cout << prime[i-1] << ' ' << ((prime[i] == n) ? prime[i+1] : prime[i]) << endl;
    }

    return 0;
}

C++: #include<iostream>

using namespace std;

long long int pri[100000];

int main()
{
  fill(pri,pri+100000,1);
  for(int i=2;i<100000;i++)
    {
      if(pri[i]==0)
	continue;
      for(int j=i+i;j<100000;j+=i)
	{
	  pri[j]=0;
	}
    }
  int n;
  for(;cin>>n;)
    {
      int a,b,c;
      for(int i=1;;i++)
	{
	  if(pri[i]==0)
	    continue;
	  else
	    {
	      c=a;
	      a=b;
	      b=i;
	      if(i>n)
		break;
	    }	  
	}
      if(a!=n)
	cout<<a<<" "<<b<<endl;
      else
	cout<<c<<" "<<b<<endl;
    }

}

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

bool isPrime(int n){
	bool bRet = true;

	if( n == 1 || n == 2 ) return true;
	for(int i = 2; i <= sqrt( (double)n ); i++){
		if( n % i == 0 ){
			bRet = false;
		}
	}
	return bRet;
}

int smallPrime(int n){
	for(int i = n - 1; i >= 2; i--){
		if( isPrime( i ) ) return i;
	}
	return 1;
}

int largePrime(int n){
	for(int i = n + 1; i < INT_MAX; i++){
		if( isPrime( i ) ) return i;
	}
}

int main(void){
	while( true ){
		int n;

		if( scanf("%d", &n) != 1 ){
			break;
		}

		printf("%d %d\n", smallPrime( n ), largePrime( n ));
	}
	return 0;
}

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

bool prime[60001];
int main(){
  memset( prime ,true ,sizeof(prime) );
  prime[0] = prime[1] = false;
  for( int i=2 ; i*i<=60000 ; i++ ){
    if( prime[i] == true ){
      for( int j=i+i ; j<=60000 ; j+=i ){
	prime[j] = false;
      }
    }
  }

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

  return 0;
}