Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var primeCount int
	for sc.Scan() {
		input := nextInt()
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		fmt.Printf("%d\n", primeCount)
		primeCount = 0
	}
}

func IsPrime(num int) bool {
	switch {
	case num == 2:
		return true
	case num < 2 || num%2 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

func next() string {
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

C++: #include <cstdio>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <functional>
#include <string.h>
using namespace std;
const int INF = 1 << 28;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,start,end) for(int i=(start);i<(end);++i)
#define pint(i) printf("%d\n",(i))
#define pint2(i,j) printf("%d %d",(i),(j))
#define pint3(i,j,k) printf("%d %d %d",(i),(j),(k))
#define pll(i) printf("%lld\n",(i))
#define pll2(i,j) printf("%lld %lld",(i),(j))
#define pll3(i,j,k) printf("%lld %lld %lld",(i),(j),(k))
#define gint(i) scanf("%d",&(i))
#define gint2(i,j) scanf("%d %d",&(i),&(j))
#define gint3(i,j,k) scanf("%d %d %d",&(i),&(j),&(k))
#define gll(i) scanf("%lld",&(i))
#define gll2(i,j) scanf("%lld %lld",&(i),&(j))
#define gll3(i,j,k) scanf("%lld %lld %lld",&(i),&(j),&(k))
#define init(tar,val) memset((tar),(val),sizeof((tar)))
#define show(tar,len) for(int i=0;i<(len);++i) \
	cout<<tar[i]<<' ';\
	cout<<endl;



/*
class bignum{
public:
bignum(int size = 4):len(size){
}
~bignum(){
}
int size()const{
return len;
}
//int get(int id)const{
//	return num[id];
//}
friend ostream &operator<<(ostream &output, const bignum &b){
bool stu = false;
for (int i = int(b.len - 1); i >= 0; --i){
if (stu)
printf("%09d", b.num[i]);
else if (b.num[i] > 0){
printf("%d", b.num[i]);
stu = true;
}
}
if (stu == false)
printf("0");
return output;
}
const bignum& operator+=(const bignum&right){
int add = 0;
for (int i = 0; i < len; ++i){
int tmp = 0;
if (i < right.size()){
tmp = right.num[i] + num[i] + add;
}
else{
tmp = num[i] + add;
}
num[i] = tmp%gap;
add = tmp / gap;
}
return *this;
}
const bignum& operator=(const bignum&right){
for (int i = 0; i <len; ++i){
num[i] = right.num[i];
}
return *this;
}
void set(int a){
for (int i = 0; i <len; ++i){
num[i] = a%gap;
a /= gap;
}
}
private:
int  num[4];
int len;
static const int gap =1000000000;
};

//int gcd(int a,int b){
//	if(b==0)
//		return a;
//	return gcd(b,a%b);
//}
//
////a*x+b*y=gcd(a,b);
//int extgcd(int a,int b,int &x,int &y){
//	int d=a;
//	if(b!=0){
//		d=extgcd(b,a%b,y,x);
//		y-=(a/b)*x;
//	}
//	else{
//		x=1,y=0;
//	}
//	return d;
//}


//inline int id(int i){
//	return i & 1;
//}
//
//inline int last(int i){
//	return (i - 1) & 1;
//}
//
//void myshow(int i){
//	rep(j, 0, ){
//		cout << dp[id(i)][j] << ' ';
//	}
//	cout << endl;
//}

//int n_stu[MAX_N];
//void n_init(){
//	rep(i, 0, n)
//		n_stu[i] = i;
//}
//int n_getf(int id){
//	if (n_stu[id] != id){
//		n_stu[id] = n_getf(n_stu[id]);
//	}
//	return n_stu[id];
//}
//bool n_same(int i, int j){
//	if (n_getf(i) == n_getf(j))
//		return true;
//	return false;
//}
//void n_union(int i, int j){
//	int fi = n_getf(i), fj = n_getf(j);
//	if (fi != fj){
//		n_stu[fi] = fj;
//	}
//}

*/

//#define my_debug



int n;
const int len = 1000005;
bool stu[len];
void setup(){
	init(stu, 1);
	stu[0] = stu[1] = false;
	rep(i, 2, len){
		if (stu[i]){
			int j = i +i;
			while (j < len){
				stu[j] = false;
				j += i;
			}
		}
	}
}
void solve(){
	int out = 0;
	rep(i, 0, n+1){
		if (stu[i])
			++out;
	}
	pint(out);
}

int main(){
#ifdef my_debug
	freopen("a.in", "r", stdin);
#endif
	setup();
	while (gint(n) != EOF){

		solve();
	}
	return 0;
}

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