Go: package main

import "fmt"

func main() {
	const MAX = 1000000
	prime := make([]int, MAX, MAX)
	check := make([]int, MAX, MAX)
	count := make([]int, MAX, MAX)

	prime[0] = 1
	prime[1] = 1

	// prime init
	for i := 2; i < MAX; i++ {
		if check[i] == 1 {
			continue
		}

		if prime[i] == 0 {
			for j := i * 2; j < MAX; j += i {
				check[j] = 1
				prime[j] = 1
			}
		}
	}

	for i := 2; i < MAX; i++ {
		cnt := 0

		if prime[i] == 0 {
			cnt = 1
		}

		count[i] = count[i-1] + cnt
	}

	for {
		var input int
		inputCount, _ := fmt.Scanf("%d", &input)
		if inputCount != 1 {
			break
		}

		fmt.Println(count[input])
	}
}

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

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    vector<int> primes;
    primes.PB(2);
    FOR(i,3,100000){
	bool flg = true;
	REP(j,primes.size()) if(i % primes[j] == 0 ) flg = false;
	if(flg) primes.PB(i);
    }

    int n;
    while(scanf("%d",&n)){
	int res = upper_bound(ALL(primes),n) - primes.begin();
	cout << res << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    vector<int> primes;
    primes.PB(2);
    FOR(i,3,300000){
	bool flg = true;
	REP(j,primes.size()) if(i % primes[j] == 0 ) {
	    flg = false;
	    break;
	}
	if(flg) primes.PB(i);
    }

    int n;
    while(true){
	cin >> n;
	if(cin.eof())break;
	int res = upper_bound(ALL(primes),n) - primes.begin();
	cout << res << endl;
    }

    return 0;
}

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

int main(){
	int n;
	int *prime,i,j;
	prime = new int[80000];
	int *answer = new int[MAX];
	int count;
	bool flag;

	count = 0;
	answer[1] = 0;
	answer[2] = 1;
	for(i = 3; i <= 1000000; 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;
		}
		answer[i] = count;
		answer[i+1] = count;
	}
	while((cin >> n)!= NULL){
		cout << answer[n] << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
	bool p[1000000] = { false };
	int n;

	while (cin >> n){
		for (int i = 2; i <n ; i++){
			for (int i2 = 2; i*i2 <= n; i2++){
				p[i*i2] = true;
			}
		}
		p[2] = false;
		p[3] = false;
		int c = 0;
		for (int i = 2; i <= n; i++){
			if (!p[i])c++;
		}
		cout << c << endl;
	}
}