Go: package main

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

func main() {
	b2i := func(b bool) int {
		if b {
			return 1
		}
		return 0
	}

	prime := func(n int) []int {
		ans := make([]int, n+1)
		for i := 2; i <= n; i++ {
			b := ans[i] == 0
			ans[i] = ans[i-1] + b2i(b)
			if b {
				for j := i * 2; j <= n; j += i {
					ans[j] = 1
				}
			}
		}
		return ans
	}
	reader := bufio.NewScanner(os.Stdin)
	primeT:=prime(999999)
	for reader.Scan() {
		n, _ := strconv.Atoi(reader.Text())
		fmt.Println(primeT[n])
	}
}

C++: #include <iostream>
#include <vector>
#include <cmath>
#include <assert.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
{
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) {
        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++;
        }
    }
    return cnt + 2;

}

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

    Integers input;
    Integers output;

    read(input);

    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);

    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;
}

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

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

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

const int kMaxN = 1000000;

int main()
{
    vector<int> prime;
    prime.reserve(100000);
    prime.push_back(2);
    prime.push_back(3);
    prime.push_back(5);
    prime.push_back(7);
    for (int i = 9; i <= kMaxN; i += 2){
        bool ok = true;
        for (int j = 0, j_max = prime.size(); j < j_max; ++j){
            if (i % prime[j] == 0){
                ok = false;
                break;
            }
        }
        if (ok) prime.push_back(i);
    }

    int n; 
    while (scanf("%d", &n) != EOF){
        int count = upper_bound(prime.begin(), prime.end(), n) - prime.begin();
        printf("%d\n", count);
    }
     
    return (0);
}

C++: import java.util.Scanner;

public class Main
{

	public static void main(String arg[])
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int count=0;
		for (int i=2; i<=n; i++)
		{
			if(prim(i))
				count++;
		}		
		System.out.println(count);
	}

	public static boolean prim(int a)
	{
		if(a<2)
			return false;
		else if (a==2)
			return true;
		
		for(int j = 2; j<a; j++)
		{
			if(a%j==0)
				return false;
		}
		return true;
	}
}

C++: #include<stdio.h>

int	main(){
	int	i,	k,	x,	cnt[1000001],	data[1000000];
	cnt[0]	=	0;
	data[0]	=	0;
	data[1]	=	0;
	for(i	=	2;	i	<=	1000000;	i++){
		data[i]	=	1;
	}
	for(i	=	2;	i	*	i	<=	1000000;	i++){
		if(data[i]){
			for(k	=	2	*	i;	k	<=	1000000;	k	+=	i){
				data[k]	=	0;
			}
		}
	}
	for(i	=	0;	i	<=	1000000;	i++){
		cnt[i	+	1]	=	cnt[i]	+	data[i];
	}
	while(1){
		scanf("%d",	&x);
		if(x	==	0)break;
		printf("%d\n",	cnt[x]);
	}
	return	0;
}

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

using namespace std;
vector<int> prime;

int calc(int);

int main(){
    int n;
    prime.push_back(2);
    while(-1!=scanf("%d", &n)){
        cout << calc(n) << endl;
    }
    return 0;
}

int calc(int n){
    int lastPrime = prime[prime.size()-1];
    if(n > lastPrime){
        for(int i=lastPrime; i<=n; i++){
            bool isPrime = true;
            for(int j=0; j<prime.size(); j++){
                int checkPrime = prime[j];
                if(i%checkPrime==0){
                    isPrime = false;
                    continue;
                }
            }
            if(isPrime) prime.push_back(i);
        }
        return prime.size();
    }else{
        for(int i=0; i<prime.size(); i++){
            if(prime[i]>=n){
                return i;
            }
        }
    }
    return -1;
}

C++: #include <iostream>

int main(void)
{
	int32_t n = 0;
	int32_t count = 0;
	int32_t count2 = 0;
	bool flag = false;

	while (std::cin >> n)
	{
		count2 = 0;
		for (int i = 2; i <= n; i++)
		{
			flag = false;
			for (int j = i-1; j > 1; j--)
			{
				if (i % j == 0)
				{
					flag = true;
					break;
				}
			}
			if (flag == false)
			{
				count2++;
			}
		}
		std::cout << count2 << std::endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,co=0;
    double he=0;
    while(cin>>n){
        he=sqrt(n);
        int ser[n+1];
        for(int i=2;i<=n;i++)ser[i]=1;
        for(int i=2;i<he;i++)if(ser[i]==1)for(int j=2;j*i<=n;j++)ser[i*j]=0;
        for(int i=2;i<=n;i++)if(ser[i]==1)co++;
        cout<<co<<endl;
        co=0;
    }
}

C++: #include    <iostream>
 
using namespace std;
 
bool F[1000003] = { false };
int DP[80000] = { 0 };
void prepa_Prime();
int count_Prime(int);
 
int main() {
    int n;

    prepa_Prime();
    while (cin >> n) {
        cout << count_Prime(n) << endl;;
    }
    return 0;
}
 
void prepa_Prime() {
    int i, c = 2;

    F[0] = F[1] = true;
    DP[0] = 1;

    DP[1] = 2;
    for (i = 4; i <= 1000003; i += 2) { F[i] = true; }
    
    for (i = 3; i <= 1000003; i += 2) {
        if (F[i] == false) {
            DP[c++] = i;
            for (int j = i * 2; j <= 1000003; j += i) {
                F[j] = true;
            }
        }
    }
}

int count_Prime(int n) {
    int i = 0;
    for (i; DP[i + 1] <= n; i++) {}
    return i;
}