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++: //--------------------------------------------------template----------------------------------------//
//c
#include <stdio.h>
#include <time.h>
#include <math.h>
//c++
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <complex>
#include <cmath>
//c++11
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
//#define sort(v,n) sort(v,v+n)
//#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.rbegin(),v.rend())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;

bool is_prime(int a) {
	int now = 2;
	while (now*now <= a) {
		if (a%now == 0)return 0;
		else now++;
	}
	return 1;
}


int main() {
	while (cin >> n) {
		ll ans = 0;
		bool a[100001];
		for (int i = 2; i <= n; i++) {
			if (a[i] == 1)continue;
			if (is_prime(i))ans++;
			else {
				for (int j = i; j <= n; j += i) {
					a[j] = 1;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
	int num;
	cin >> num;

	if(num<2){
		cout <<"0"<<endl;
		return 0;
	}

	vector<bool> a(num,true);
	int cnt = num-2;
	for(int ix = 2;ix != num;++ix){
		int jx = 1;
		while((++jx)*ix < num){
			if(a[ix*jx]){
				a[ix*jx] = false;
				cnt--;
			}
		}
	}

	cout <<cnt<<endl;

	return 0;
}

C++: #include<stdio.h>

int main(){
  const int MAX_V = 1000000;
  int prime[MAX_V+1];
  int i, k, v;
  int e, f, ans;
  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;
      }
    }
  }
  for(e = 0; e < 30; e++){
    int count = 0;
    scanf("%d", &v);
    for(f = 2; f <= v; f++){
      ans = prime[f];
      if(ans == 1){
        count++;
      }
    }
    printf("%d\n", count);
  }
  return 0;
}

C++: #include <cstdio>

int Eratos[1000000];

int main()
{
	Eratos[0] = Eratos[1] = 0;
	for (int i = 2; i < 1000000; i++){
		Eratos[i] = 1;
	}
	for (int i = 2; i < 1000; i++) {
		if (Eratos[i]) {
			for (int j = 2 * i; j < 1000000; j += i) {
				Eratos[j] = 0;
			}
		}
	}
	int n,res;
	res = 1;
	for (int i = 2; i < 1000000; i++) {
		if (Eratos[i]) {
			Eratos[i] = res;
			res++;
		}
	}
	while (scanf("%d", &n)) {
		res = 0;
		while (!Eratos[n]) {
			n--;
		}
		printf("%d\n",Eratos[n]);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cmath>
#include <assert.h>
#include <time.h>


/**
* @brief 可変長配列
*/
class Integers : public std::vector<int>
{
public:
    /**
    * @fn void add(int n)
    * @brief 要素を追加する
    * @param[in] val 追加対象
    */
    void add(int val)
    {
        this->push_back(val);
    }

    /**
    * @fn int indexOf(int idx)
    * @brief 指定した要素の値を取得する
    * @param[in] idx 指定する要素
    * @return int 要素の値
    */
    int indexOf(int idx)
    {
        assert(0 <= idx && getLength() - 1 >= idx);

        return static_cast<int&>(this->at(idx));
    }

    /**
    * @fn int getLength()
    * @brief 配列の長さを取得する
    * @return int 長さ
    */
    int getLength()
    {
        return this->size();
    }
};

class PrimeNumber
{
public:
    /**
    * @fn int getPrimeNumber(int data)
    * @brief dataまでの素数の個数を取得する
    * @param[in] data 入力データ
    * @return int 素数の数
    */
    int getPrimeNumber(int data);
};

class Control
{
private:
    clock_t start, end;

public:
    /**
    * @fn bool executeEx()
    * @brief 入力の最後まで整数nを読み込み、n以下の素数の数を出力する
    * @return bool 入力値が範囲内またはデータセットが30以下ならtrueを、そうでなければfalseを返す
    */
    bool executeEx();

private:
    /**
    * @fn bool check(Integers& target)
    * @brief 入力範囲内かチェックする
    * @param[in] target チェック対象
    * @return bool 入力範囲内ならtrueを、そうでなければfalseを返す
    */
    bool check(Integers& target);

    /**
    * @fn void read(Integers& target)
    * @brief 入力終了まで読み込む
    * @param[out] target 入力データ
    */
    void read(Integers& target);

    /**
    * @fn void write(Integers& target)
    * @brief 素数の個数を出力する
    * @param[in] target 出力対象
    */
    void write(Integers& target);
};

//------------------------------------------------------

int PrimeNumber::getPrimeNumber(int data)
{
    int cnt = 0;
    
    if (1 == data)
        return 0;

    if (2 == data)
        return 1;

    if (3 == data)
        return 2;

    for (int i = 5; i <= data; i += 2) {
        if (0 == i % 3 || 0 == i % 5 || 0 == i % 7)
            continue;

        int square = (int)std::sqrt(i);
        bool isNotPrime = false;
        for (int j = 3; j <= square; j += 2) {
            if (0 == i % j) {
                isNotPrime = true;
                break;
            }
        }
        if (!isNotPrime) {
            cnt++;
            continue;
        }
    }

    return cnt + 2;

}

bool Control::executeEx()
{
    static const int DataMax = 30;

    Integers input;
    Integers output;

    read(input);

    start = clock();

    if (DataMax < input.getLength() || !check(input))
        return false;

    for (int i = 0; i < input.getLength(); i++) {
        output.add(PrimeNumber().getPrimeNumber(input.indexOf(i)));
    }

    write(output);

    end = clock();
    std::cout << (double)(end - start) / CLOCKS_PER_SEC;

    return true;
}

bool Control::check(Integers& target)
{
    static const int Min = 1;
    static const int Max = 999999;

    for (int i = 0; i < target.getLength(); i++) {
        if (Min > target.indexOf(i) || Max < target.indexOf(i))
            return false;
    }

    return true;
}

inline void Control::read(Integers& target)
{
    int input = 0;

    while (std::cin >> input)
        target.add(input);
}

inline void Control::write(Integers& target)
{
    for (int i = 0; i < target.getLength(); i++) {
        std::cout << target.indexOf(i) << std::endl;
    }
}

/**
* @fn int main()
* @brief エントリポイント
*/
int main()
{
    if (!Control().executeEx())
        return 1;
}

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

int main(){
	int n;
	int prime[MAX],i,j;
	int count;
	bool flag;

	while((cin >> n)!= NULL){
		count = 0;
		for(i = 3; i <= n; i+=2){
			flag = true;
			for(j = 0; j < count; j++){
				if(i % prime[j] == 0){
					flag = false;
					break;
				}
				if(prime[j] * prime[j] > i) break;
			}
			if(flag == true){
				prime[count++] = i;
			}
		}
		if(n > 1)	count++; //2
		cout << count << endl;
		//delete[] prime;
	}
	return 0;
}