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<cstdio>
#include<cstdlib>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{ 
  const int END = -1;
  const int NUM = 50022;
  int num;
  int i,index,index2,index3;
  
  cin >> num;

  vector<int> eratos(NUM);

  for(i = 0;i < NUM - 1 ; i++)
    eratos[i] = i+2;
  eratos[i] = END;
 
  while(!cin.eof()){
    i = 0;
    index3 = 0;
  while(eratos[i]!=END)
    {
      if(eratos[i]!=0)
        {
          index = i + 1;
          index3 = i + 1;
          while(eratos[index]!=END)
            {
              if(eratos[index]%eratos[i] != 0)
                {
                  eratos[index3] = eratos[index];
                  index3++;
                }
              index++;
            }
          eratos[index3] = END;
        }
      i++;
    }
 
  for(i = 0; i < index3; i++)
    {
      if(eratos[i]==num)
        {
          cout << eratos[i-1] << " " << eratos[i+1] << endl;
          break;
        }
      else if(eratos[i] > num)
        {   
              cout << eratos[i-1] << ' ' << eratos[i] << endl;
              break;
        }
    }
    cin >> num;
  }
  return 0;
}

C++: using System;
using System.Collections.Generic;

namespace _0044
{
    class Program
    {
        static void Main(string[] args)
        {
            var primeList = new List<int>();
            for (int i = 1; i < 50022; i++)
            {
                if (IsPrime(i))
                {
                    primeList.Add(i);
                }
            }

            while (true)
            {
                var input = Console.ReadLine();

                if (string.IsNullOrEmpty(input)) { break; }

                var number = int.Parse(input);
                var previousPrimeNumber = 0;
                var nextPrimeNumber = 0;

                foreach (var primeNumber in primeList)
                {
                    if (primeNumber < number)
                    {
                        previousPrimeNumber = primeNumber;
                    }
                    else if (primeNumber > number)
                    {
                        nextPrimeNumber = primeNumber;
                    }

                    if (nextPrimeNumber != 0)
                    {
                        break;
                    }
                }
                Console.Write("{0} {1}\n", previousPrimeNumber, nextPrimeNumber);
            }
        }

        public static bool IsPrime(int number)
        {
            if (number <= 1)
            {
                return false;
            }
            else if (number <= 3)
            {
                return true;
            }
            else if ((number % 2) == 0)
            {
                return false;
            }
            else
            {
                for (int i = 3; i <= (int)Math.Sqrt(number); i += 2)
                {
                    if (number % i == 0)
                    {
                        return false;
                    }
                }
            }
            return true;
        }
    }
}

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



bool judgePrimenum(int n){

	int sqr = sqrt((double)n);

	if(n%2 == 0)return false;

	for(int i=3;i<=sqr;i+=2){
		if(n%i == 0)return false;
	}

	return true;
}




int main(){
	while(true){
		int n, min=0, max=0, i=1;
		cin >> n;

		while(min==0 || max==0){
			if( max==0 && judgePrimenum(n+i) )max=n+i;
			if( min==0 && judgePrimenum(n-i) )min=n-i;
			++i;
		}

		cout << min << " " << max << endl;
	}
	return 0;
}

C++: #include <cstdio>

using namespace std;

bool is_prime(int n) {
    for(int i=2; i*i<=n; i++) {
        if(n % i == 0) return false;
    }
    return n != 1;
}

int main(void)
{
    int n;
    while(~scanf("%d", &n)) {
        for(int i=n-1; i>=0; i--) {
            if(is_prime(i)) {
                printf("%d ", i);
                break;
            }
        }
        for(int i=n+1; ; i++) {
            if(is_prime(i)) {
                printf("%d\n", i);
                break;
            }
        }
    }

    return 0;
}

C++: #include <iostream>
using namespace std;
bool p(int n) {
  if (n == 2) return true;
  if (n % 2 == 0) return false;
  for (int i = 3; i * i < n; i += 2)
    if(n % i == 0) return false;
  return true;
}
int main() {
  int i, n;
  while (cin >> n) {
    for (i = n - 1; ; i--) if (p(i)) { cout << i << ' '; break; }
    for (i = n + 1; ; i++) if (p(i)) { cout << i << endl; break; }
  }
}

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

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

int main(){
    int bigger, smaller, a;
    while (cin >> a){
	bigger = smaller = a;
	while (1){
	    if (isprime(++bigger)) break;
	}
	while (1){
	    if (isprime(--smaller)) break;
	}
	cout << smaller << " " << bigger << endl;
    }
}

C++: #include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
using namespace std;



int main(){
	int d,arr[100000],count,ch;
	arr[0]=2;
	count =0;
	for(int i=3;i<=50100;i++){
		ch=0;
		for(int j=0;j<=count;j++){
			if(i%arr[j] == 0)ch=1;
		}
		if(ch == 0){
			count++;
			arr[count]=i;
		}
	}
	while(scanf("%d",&d) != EOF){
		for(int i=0;;i++){
			if(arr[i]==d){
				printf("%d %d\n",arr[i-1],arr[i+1]);
				break;
			}
			if(arr[i]>d){
				printf("%d %d\n",arr[i-1],arr[i]);
				break;
			}
		}
	}
		
	
	return 0;
}

C++: #include<iostream>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
const int M = (1e6);
int p[M];
void isPrime(){
  rep(i,M)p[i] = true;
  p[0] = p[1] = false;
  loop(i,2,M){
    if(p[i])
      for(int j = i + i ; j < M ; j += i)
	p[j] = false;
  }
}
int main(void){
  isPrime();
  int n;
  while(cin>>n){
    int i = n - 1;
    while(!p[i--]);cout<<++i<<" ";
    i = n + 1;
    while(!p[i++]);cout<<--i<<endl;
  }
}

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

int* primeNumberList(int n){
    int *list = new int[n];
    
    for(int i=2;i<=n;++i){
        list[i-1]=1;
    }
    
    for(int i=2;i<=n;++i){
        if(list[i-1] == 1){
            for(int j=2*i;j<=n;j+=i){
                list[j-1] = 0;
            }
        }
    }
    
    return list;
}
int main(){
    int max = 60000;
    int *pl = primeNumberList(max);
    int n,plowermax,pgreatermin;
    
    while(cin>>n){
        for(int i=n-1;i>=1;--i){
            if(pl[i-1] == 1){
                cout << i << " ";
                break;
            }
        }
        for(int i=n+1;i<=60000;++i){
            if(pl[i-1] == 1){
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}