Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func check(n int) int {
	eratos := make([]bool, n+1)
	cnt := 0
	for i := 2; i < len(eratos); i++ {
		if !eratos[i] {
			cnt++
			for j := i*i; j < len(eratos); j += i {
				eratos[j] = true
			}
		}
	}
	return cnt
}

func main() {
	for scanner.Scan() {
		n := nextInt()
		fmt.Println(check(n))
	}
}

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