Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 0
                                }
                        }
                }
        }
}

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

using namespace std;


vector<int> era(int n){
	vector<int> prime;
	bool *is_prime = new bool[n+1];
	fill(is_prime,is_prime+n+1,true);
	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i <= n; i++){
		if(is_prime[i]){
			prime.push_back(i);
			for(int j = i*2; j <= n; j+=i){
				is_prime[j] = false;
			}
		}
	}
	delete []is_prime;
	return prime;
}

int main(){

	int n;
	while(1){
		if(cin.eof())
			break;
		cin >> n;
		vector<int> p = era(n);
		cout << p.size() << endl;
	}

	return 0;
}

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

int count(int n);

int main(void){
	while (true){
		int n; cin >> n;
		if (!n){
			break;
		}
		cout << count(n) << endl;
	}
	return 0;
}

int count(int n){
	int ct = 0;
	bool *prime = new bool[n];
	//bool prime[999999];
	for (int i = 0; i <= n;i++){
		prime[i] = 0;
	}
	prime[2] = 1;
	for (int i = 3; i <= n; i = i + 2){
		prime[i] = 1;
	}
	for (int i = 3; i <= n; i = i + 2){
		if (prime[i] == 0) continue;
		for (int j = i * 2; j <= n; j = j + i){
			prime[j] = 0;
		}
	}
	for (int i = 3; i <= n; i = i + 2){
		if (prime[i] == 1) ct++;
	}
	ct++; //2を数えていない分
	return ct;
	delete[] prime;
}

C++: /*
 * hujx.cpp
 *
 *  Created on: 2015年5月21日
 *      Author: dell
 */
#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<time.h>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<limits.h>
#include<map>
#include<set>
#include<bitset>
//#define ONLINE_JUDGE
#define eps 1e-5
#define INF 0x7fffffff
#define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define sfs(a) scanf("%s",a)
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define pf(a) printf("%d\n",a)
#define pfI(a) printf("%I64d\n",a)
#define pfs(a) printf("%s\n",a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,num) scanf("%d%d%d",&a,&b,&num)
#define for1(i,a,b) for(int i=(a);i<b;i++)
#define for2(i,a,b) for(int i=(a);i<=b;i++)
#define for3(i,a,b)for(int i=(b);i>=a;i--)
#define MEM1(a) memset(a,0,sizeof(a))
#define MEM2(a) memset(a,-1,sizeof(a))
#define ll long long
const double PI=acos(-1.0);
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
using namespace std;
//#pragma comment(linker,"/STACK:1024000000,1024000000")
int n,m,c;
#define N 210
#define M 1000100
#define Mod 1000000000
#define p(x,y) make_pair(x,y)
const int MAX_len=550;
int f[M],prime[M];
int vis[M];
int tot;
void get_Prime(){
	memset(f,0,sizeof f);
	tot=0;
	int p = (int)sqrt(M)+1;
	for(int i=2;i<p;i++){
		if(f[i]) continue;
		for(int j=i;i*j<M;j++)
			f[i*j] = 1;
	}
	for(int i=2;i<M;i++){
		f[i] ^= 1;
		f[i] += f[i-1];
	}
}
int main(){
    get_Prime();
    while(sf(n)!=EOF){
    	pf(f[n]);
    }
    return 0;
}

C++: #include <iostream>
#include <math.h>

using namespace std;

int main() {
  int N = 1000001;
  int primes[N];
  int i, j;
  for (i = 2; i < N; i++) {
    primes[i] = 1;
  }

  for (i = 2; i <= int(sqrt(N)); i++) {
    if (primes[i]) {
      for (j = i*i; j < N; j+=i) {
        primes[j] = 0;
      }
    }
  }

  int n;
  while (cin >> n) {
    int ans = 0;
    for (i = 2; i <= n; i++) {
      ans += primes[i];
    }
    cout << ans << endl;
  }

  return 0;
}

C++: #include <iostream>

using namespace std;

int sang(long long  n,bool *s,long long  *p,long long &m){
	m = 0;
	for(long i = 2; i<=n;i++){
		s[i] = 2;
	}
	for(long i = 2; i<=n; i++){
		if(s[i]){
			p[m++] = i;
			for(long j = i * i; j<= n ; j += i){
				s[j] = 0;
			}
		}
	}
	return m;
}
int main(){
	bool s[100005];
	long long  n,p[100005],m;

	while(cin>>n){
		sang(n,s,p,m);
		cout<<m<<endl;
	}
	return 0;
}

C++: #include<iostream>
#define m 1000000
using namespace std;

bool ba[m] = { true };
int cp(int x) {
	if (x < 2)return 0;
	if (x == 2)return 1;

	int co = 0;
	for (int i = 0; i < m; i++) {
		ba[i] = { true };
	}
	for (int i = 2; i*i <= x; i++) {
		if (ba[i]) {
			for (int j = i*i; j <= x; j += i) {
				ba[j] = { false };
			}
		}
	}
	for (int i = 2; i <= x; i++) {
		if (ba[i]) {
			++co;
		}
	}
	return co;
}

int main() {
	int x;
	while (cin >> x) {
		cout << cp(x) << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <cmath>

using namespace std;

bool isPrime(int n)
{

    int i, sqr;

    if(n <= 1){
        return false;
    }
    else if(n == 2){
        return true;
    }
    else{
        sqr = sqrt(n);
        for(i = 2; i <= sqr; i++){
            if(n % i == 0){
                return false;
            }

        }

        return true;
    }
}

int main(void)
{

    int n, count = 0;

    scanf("%d", &n);

    for(int i = 1; i <= n; i++){
        if(isPrime(i)){
            count++;
        }
    }
    printf("%d\n", count);



    return 0;
}