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++: /*
C++ ???????????????????????????????????¬??????
??????AOJ-ITP1??????????????????
*/
#define _USE_MATH_DEFINES

#include <iostream> // ?¨??????\??????
#include <fstream>  // ??????????????\??????
#include <string>   // ???????????¢???
#include <vector>   // ???????????????
#include <cmath>    // ??°??????
#include <iomanip>  // stream???????????¢???
#include <algorithm>// max??¢??°??????

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;        // ????´???°????????????????????????
using std::fixed;         // ???????????????????¨???????????????????????????????
using std::setprecision;  // ?????°????°???°?????\???????????°????????????????????¨????????\???

int main() {
	int a;
	int count;
	int ccount;
	vector<int> c = { 0 };
	while (cin >> a)
	{
		a = a + 1;
		count = 0;
		
		// ?????§????????§????????????0??§???????????????
		c.resize(a);
		
		// 2*i????????§????????§?????????????????????1?????????
		for (size_t i = 2; i < a; i++)
		{
			for (size_t j = 2; i*j < a; j++)
			{
				c[i*j] = 1;
			}
		}
		c[0] = c[1] = 1;
		// ??????????????????0??????????????°????????????
		for (size_t i = 0; i < a; i++)
		{
			if (c[i] == 0) {
				count++;
			}
		}
		cout << count << endl;
	}
	return 0;
}

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

using namespace std;
const int MAX = 1000000;
vector <int> primeCountList(MAX, 0);//indx:number value:primeCount

void setPrimeCount()
{
    int primeCount = 1;
    for(int i=3;i<=MAX;i+=2)
    {
        bool isPrime = true;
        for(int j=3;j*j<=i;j+=2)
        {
            if(i%j == 0)
            {
                isPrime = false;
                break;
            }
        }
        primeCountList[i-1] = primeCount;
        if(isPrime)
        {
            primeCount++;
            primeCountList[i] = primeCount;

        }
        else
        {
            primeCountList[i] = primeCount;
        }

    }
    primeCountList[2] = 1;

}
/*
 * getPrimeNumber:0009
 */
int main()
{
    setPrimeCount();
    int n;
    while(cin >> n)
    {
        cout << primeCountList[n] << endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int isprime(int x){
	if(x < 2){
		return false;
	}else if(x==2){
		return true;
	}else{
		for(int i=3;i<x;i=i+2){
			if(x%i==0){
				return false;
			}
		}
		return true;
	}
}
int main(){
	int n;
	while((cin >> n)){
	int a = 0;
	for(int i=2;i<=n;i++){
		if(isprime(i)){
			a++;
		}
	}
	cout << a << endl;
	}
	return 0;
}