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++: /*
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;
}