Go: package main

// https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)

	for {
		n, err := nextInt()
		if err != nil {
			break
		}
		maybePrime := make([]bool, n+1)
		for i := 0; i <= n; i++ {
			maybePrime[i] = true
		}

		maybePrime[0] = false
		maybePrime[1] = false
		for i := 2; i <= int(math.Sqrt(float64(n)))+1; i++ {
			j := i * 2
			for j <= n {
				maybePrime[j] = false
				j += i
			}
		}

		nPrimes := 0
		for _, p := range maybePrime {
			if p {
				nPrimes++
			}
		}
		// fmt.Println(maybePrime)
		fmt.Println(nPrimes)
	}
}

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

int main()
{
	bool is_prime[1000000];
	memset(is_prime,false,sizeof(is_prime));
	for(int i=2;i<1000000;i++){
		if(!is_prime[i]){
//			cout<<i<<endl;
			for(int m=i*2;m<1000000;m+=i){
				is_prime[m]=true;
			}
		}
	}
	int n;
	while(cin>>n){
		int ans=0;
		for(int i=2;i<=n;i++){
			if(!is_prime[i]) ans++;
		}
		cout<<ans<<endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
int main()
{
	int i = 0, maxV = INT_MIN, A[30] = {};
	for (int k; cin >> k; ) {
		A[i++] = k;
		if (maxV < k)
			maxV = k;
	}
	int s = maxV + 1;
	vector<long> vP(s, 0);
	int c = 0, j;
	for (int k = 2; k < s; ++k){
		if (vP[k] == 0){
			vP[k] = ++c;
			for (j = 2; j * k < s; ++j)
				vP[j * k] = -1;
		}
		else if (vP[k] == -1)
			vP[k] = c;		
	}
	for (j = 0; j < i; ++j)
		cout << vP[A[j]] << "\n";
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int a,n[100000],j,o=0;
	for(int i=2;i<=99999;i++){
		n[i]=1;
		
	}
	n[0]=n[1]=0;
		for( j=2;j<=99999;j++){
			if(n[j]){
				for(int k=j*2;k<=9999;k+=j){
				n[k]=0;
				}
			}
		}
		while(cin>>a){
	for(int k=2;k<=a;k++) if(n[k]) o++;
	cout<<o<<endl;
		}
}

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

int main(){
    int n, cnt;
    bool prime[1000000] = {false, false};

    for(int i = 2;i < 1000000;i++){
        prime[i] = true;
    }
    
    for(int i = 2;i <= sqrt(1000000);i++){
        if(prime[i]){
            for(int j = 2*i;j <= 1000000;j++){
                if(j%i == 0){
                    prime[j] = false;
                }
            }
        }
    }
    
    while(cin >> n){
        cnt = 0;

        for(int i = 2;i <= n;i++){
            if(prime[i]){
                cnt++;
            }
        }
        
        cout << cnt << endl;
    }

    return 0;
}

C++: #include <iostream>

using namespace std;

bool is_prime(int n) {
        if (n < 2) {
                return false;
        }

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

        return true;
}

int number_of_primes_under(int n) {
        if (n < 2) {
                return 0;
        }

        int count = 1;
        int i;
        for (i=3; i <= n; i = i + 2) {
                if (is_prime(i)) {
                        count++;
                }
        }

        return count;
}
int main(void) {
        int n;
        while(cin >> n) {
                cout << number_of_primes_under(n);
                cout << endl;
        }

        return 0;
}

C++: #include <iostream>
using namespace std;
bool prime[1000000];
void sieve() {
    fill_n(prime, 1000000, true);
    for (int i=2; i<=1000; ++i) {
        if (prime[i]) {
            for (int j=i*i; j<1000000; j+=i) {
                prime[j] = false;
            }
        }
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    sieve();

    int memo[1000000];
    for (int i=1; i<1000000; ++i) {
        memo[i] = memo[i-1]; 
        if (prime[i]) {
            memo[i] ++; 
        }
    }

    int n;
    while (cin >> n) {
        int cnt = 0;
        for (int i=2; i<=n; ++i) {
            if (prime[i]) {
                cnt ++;
            }
        }
        cout << cnt << "\n";
    }
    return 0;
}

C++: /// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009
/// http://www.tsg.ne.jp/TT/tsg/c/mansaku/P01.html
#include<iostream>
#include<cmath>
using namespace std;

int main(){
    int n;
    while(~scanf("%d", &n)){
        int cnt = 0;
        for(int i = 3; i<=n; i+=2){
            int k= 0;
            for(int j=3; j<sqrt(i); j+=2){
                if(i%j==0){
                    k=1;
                    break;
                }
            }
            if(k==0) cnt++;
        }
        printf("%d\n", cnt);

    }

    return 0;
}

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

int main(void){
int unti[100002] = {0};
fill(unti,unti + 100001,0);
for(int n = 2;n < 100001;n++)
{
if(unti[n] == 0)
{
for(int a = 2;(a * n) < 100001;a++)
{
	unti[a * n]++;
}
}
}
int b;
while(cin >> b )
{
int cnt = (count(unti,unti+b+1,0) - 2);
cout << cnt << endl;
}
return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <vector>
using namespace std;

// chack wheather a number n is a natural number
bool checkNaturalNum(int n) {
  int count = 0;
  for (int i = 1; i < n + 1; i++) {
    if (n % i == 0) {
      count++;
    }
  }

  if (count == 2) {
    return true;
  } else {
    return false;
  }
}

int countNaturalNum(int n) {
  int count = 0;
  for (int i = 1; i < n + 1; i++) {
    if (checkNaturalNum(i)) {
      count++;
    }
  }
  return count;
}

int main(int argc, char const *argv[]) {
  int num;
  while (std::cin >> num) {
    std::cout << countNaturalNum(num) << '\n';
  }
  return 0;
}

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

int main() {
	// your code goes here
	int nu[30];
	int num;
	int count = 0;
	int max = 29;
	for(int x=0;x<30;x++){
		nu [x] = -1;
		cin >> nu[x];
		if (nu[x] == -1) {
			max = x;
			break;
		}
	}
	for (int y=0;y<max;y++) {
		num = nu[y];
		count = 0;
		
		for (int i = 1;i<=num;i++) {
		if(i%2==0) {
			//cout <<"2: "<<i<<endl;
			count ++;
			continue;
		}
		for (int j=3;j<i;j=j+2) {
			if (i%j==0) {
				count ++;
				//cout <<"i: "<<i<<" j: "<<j<<endl;
				break;
			}
		}
	}
	cout << (num-count) <<endl;
	//cout << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
typedef long long int LL;
#define MOD 1000000007

LL pow(LL m, LL n)
{
	LL res = 1,x = 1,a = m;
	while (x <= n) {
		if ((x & n) > 0) {
			res *= a;
			res %= MOD;
			a %= MOD;
		}
		a *= a;
		x <<= 1;
	}
	res %= MOD;
	return res;
}

int main()
{
	LL m, n;
	cin >> m >> n;
	cout << pow(m,n) << endl;
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  int n;
  vector<int> v;
  while (cin >> n) {
    if (v.size() >= n + 1) {
      cout << accumulate(v.begin(), v.end() - (v.size() - (n + 1)), 0) << endl;
      continue;
    }
    v.resize(n + 1);
    fill(v.begin(), v.end(), 1);
    v[0] = 0;
    v[1] = 0;
    for (int i = 0; i * i < v.size(); ++i) {
      while (v[i] == 0) ++i;
      for (int m = i + 1; m < v.size(); ++m) {
        if (m % i == 0) {
          v[m] = 0;
        }
      }
    }
    cout << accumulate(v.begin(), v.end(), 0) << endl;
  }
  return 0;
}