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 <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

int main() {
	const int MAX_V = 100000;
	int prime[MAX_V+1];
	int i, k, v;
	for(i = 2; i <= MAX_V; i++) {
		prime[i] = 1;
	}
	for(i = 2; i*i <= MAX_V; i++) {
		if(prime[i]) {
			for(k = 2 * i; k <= MAX_V; k += i) {
				prime[k] = 0;
			}
		}
	}
	scanf("%d", &v);
	int count = 0;
	for(i=0;i<=v;i++){
		int isprime = prime[i];
		if(isprime) count ++;
	}
	printf("%d",count);
	return 0;
}

C++: #include <stdio.h>
#include <string.h>
int main(void){
    int n=999999,a,b,c;
    char x[1000000];
    memset(x,0,sizeof(x));
    for(a=2,c=0;a<=n;a++){
        if(x[a]){x[a]=c;continue;}
        x[a]=++c;
        for(b=a*2;b<=n;b+=a)x[b]=-1;
    }
    while(~scanf("%d",&n)){
        printf("%d\n",x[n]);
    }
    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
static const double EPS = 1e-10;

int main(){
	vector<int> p;
	bool b;
	int n;

	while(cin >> n){
		p.clear();
		p.push_back(2);
		for(int i = 3; i <= n; i++){
			b = true;
			for(int j = 0; j < p.size(); j++){
				if(p[j]*p[j] > i){
					break;
				}
				if(i % p[j] == 0){
					b = false;
					break;
				}
			}
			if(b){
				p.push_back(i);
			}
		}
		cout << p.size() << endl;
	}

	return 0;
}

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


int main(){
	bool work[MAX + 1];
	int num, ans = 0;

	// 入力
	cin >> num;

	// 初期化
	for(int i = 0; i <= MAX; i++){
		if(i < 2){
			work[i] = false;
		}else{
			work[i] = true;
		}
	}

	// エラトネスのふるい
	for(int i = 2; i < sqrt((double)MAX) + 1; i++){
		if(work[i] == true){
			for(int j = i * 2; j < MAX; j += i){
				work[j] = false;
			}
		}
	}

	// 計算
	for(int i = 0; i <= num; i++){
		if(work[i] == true){
			ans++;
		}
	}

	// 出力
	cout << ans << endl;

	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
typedef pair<int,int> pii;

inline bool IN(int x, int y, int w, int h)
{
    return 0 <= x && x < w && 0 <= y && y < h;
}


int main()
{
	int n;
	cin >> n;
		vi pn(1000000,1);
	pn[0]=0;
	pn[1]=0;
	int ans=0;
	for(int i=2;i<=n;i++){
		if(pn[i]==1){
			for(int j=i+1;j<=n;j++){
				if(!(j%i)){
					pn[j]=0;
				}
			}
		}
	}
	rep(i,n+1){
		if(pn[i])ans++;
	}
	cout << ans << endl;


}

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

 void prima()
    {
        bool isprima;
        int a, n, c = 0;
        while(cin >> a && c < 30)
        {
            n = 0;
            for(int i = 2; i <= a; i++)
            {
                isprima = true;
                for(int j = 2; j < i; j++)
                {
                    if( i == 2)
                    {
                        isprima = true;
                        break;
                    }
                    else if(i % j == 0)
                    {
                        isprima = false;
                        break;
                    }
                }
                if(isprima) n++;
            }
            cout << n << endl;
            c++;
        }
    }

int main()
{
   prima();
}

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

int main(){
	int i=0,k=2,source[30];
	while(cin >> source[i]) i++;
	int m = max(source[0],source[i]);
	bool hurui[1000000];
	memset(hurui,1,sizeof(hurui));
	for (int j=2;j<=m;j++,k=2)
	{
		if (!hurui[j]) continue;
		while(j*k < m)hurui[j*k]=false,k++;
	}
	hurui[0]=0,hurui[1]=0;
	for (int j=0;j<i;j++){
		int count=0;
		for (k=2;k<=source[j];k++) count += !!hurui[k];
		cout << count << endl;
	}
}

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

int main()
{
        long long max;
        vector<int> pn;
        bool npn[1000000];
        npn[0] = npn[1] = true;


        while(cin >> max){
                for(long i=2;i<max;i++){
                        if(npn[i]) continue;
                        pn.push_back(i);
                        for(long j=i*1;j<=max;j+=i)npn[j] = true;
                }

                cout << pn.size() << "\n";
                for(long i=2;i<=max;i++)npn[i] = false;
                pn.clear();
        }

        return 0;
}

C++: #include <stdio.h>
#include <algorithm>  // fill 関数を使うのに必要
#define PN_NUM 1000000    // 1000000 未満の非負数を素数判定する
using namespace std;

bool prime_number[PN_NUM];

// エラトステネスのふるい
void set_prime_number(bool* array) {

  fill(array, array + PN_NUM, true); // array の全要素を true にする
  array[0] = array[1] = false; // 0 と 1 は素数ではない
  for (int i = 2; i < PN_NUM; i++) {
    if (!array[i])
      continue;
    for (int j = i * 2; j < PN_NUM; j += i) {
      array[j] = false; // 素数の倍数は，素数ではない
    }
  }

}

int main() {
  int cnt, n;

  set_prime_number(prime_number);
  while (scanf("%d", &n) != EOF) {
    cnt = 0;
    for (int i = 0; i <= n; i++) {
      if (prime_number[i]) // i が素数ならば
        cnt++;             // cnt をインクリメント
    }
    printf("%d\n", cnt);   // cnt を出力
  }

  return 0;
}