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] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

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

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

#define Max 1000000
int Prime[Max] = {};

int main()
{
	//?????????
	for (int i = 2; i < Max; i++)
	{
		Prime[i] = 1;
	}
	//??¨??????????????????????????????
	for (int i = 2; i*i < Max; i++)
	{
		if (Prime[i] == 1)
		{
			for (int j = i * 2; j < Max; j += i)
			{
				Prime[j] = 0;
			}
		}
	}
	//?´???????????¨????
	for (int i = 2; i < Max; i++)
	{
		Prime[i] += Prime[i - 1];
	}

	int n;
	while (cin >> n)
	{
		cout << Prime[n] << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	while (1)
	{
		int tmp;

		cin >> tmp;

		vector<int> prime;

		for (int i(2); i <= tmp; ++i)
		{
			for (vector<int>::iterator i2(prime.begin()), n2(prime.end()); i2 != n2; ++i2)
			{
				if ((i % *i2) == 0)
				{
					goto nx;
				}
			}

			prime.push_back(i);
		nx:;
		}

		cout << prime.size() << endl;

		if (cin.eof()) { break; }
	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

int prime[1000000];
signed main(void) {
  REP(i, 1000000) prime[i] = 1;
  prime[0] = prime[1] = 0;
  for (int i = 2; i * i <= 1000000; i++) {
  	if (prime[i]) {
  		for (int j = 2 * i; j <= 1000000; j += i) {
  			prime[j] = 0;
  		}
  	}
  }
  //REP(i, 10) cout << prime[i] << " "; cout << endl;
  FOR(i, 1, 1000000) {
    prime[i] += prime[i-1];
    //cout << prime[i] << endl;
  }
  int n;
  while (cin >> n) {
    cout << prime[n] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstring>
using namespace std;

bool primeFlg[1000000];

void makePrime(){
  memset(primeFlg, true, sizeof(primeFlg));
  primeFlg[0] = primeFlg[1] = false;

  for(int i = 2; i * i <= 1000000; i++){
    if(primeFlg[i]){
      for(int j = i + i; j < 1000000; j += i){
        primeFlg[j] = false;
      }
    }
  }
}

int main(){
  int n;

  makePrime();

  while(cin >> n){
    int primeCount = 0;

    for(int i = 0; i <= n; i++){
      primeCount += primeFlg[i];
    }

    cout << primeCount << endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main (int argc, char * const argv[]) {
    // insert code here...
    int n, N=1000000;
	bool p[1000000]={0};

	for(int i=2;i<N;i++){
		if(!p[i]){
			for(int j=i+i;j<N;j+=i){
				p[j]=1;
			}
		}
	}
	
	while(cin >> n){
		int count =0;
		for(int i=2;i<=n;i++){
			if(!p[i])count++;
		}
		cout<<count<<endl;
	}
	
	return 0;
}

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

using namespace std;

int main(){
  int k, n;
  vector<int> prime;
  vector<int>::iterator i, j;

  while(cin >> n){
    for(k=2; k<=n; ++k)
      prime.push_back(k);
    
    i = prime.begin();
    while(i != prime.end()){
      j = i + 1;
      while(j != prime.end()){
	if((*j)%(*i) == 0)
	  j = prime.erase(j);
	else
	  ++j;
      }
      ++i;
    }
    cout << prime.size() << endl;
    prime.clear();
  }

  return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;

int main()
{
	int counter=1,n,flag;
	
	while(cin>>n)
	{
		if(n<=1) 
		{
			cout<<'0'<<endl;
			break;
		}

		for(int i=3;i<=n;i+=2)
		{
			flag=1;
			for(int j=3;j<=sqrt(n);j+=2)
				if(i%j==0)
				{
					flag=0;
					break;
				}
			if(flag==1)
				counter++;
		}
		cout<<counter<<endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
 
#define maxPN 1000000
#define PNs  1000100
int countPN = 0, countPNs = 0;
long long PrimeNum[maxPN], temp;
bool PN[PNs];
 
bool IsPrimeNumber(long long x);
 
void PrimeN(){
    int i, j;
    PrimeNum[0] = 2;
    PN[2] = true;PrimeNum[countPN++] = 2;
    PN[3] = true;PrimeNum[countPN++] = 3;
//  PN[5] = true;PrimeNum[countPN++] = 5;
     
    for(i = 6; i  < PNs;i+=6){
        if(IsPrimeNumber(i-1)){
            PrimeNum[countPN++] = i-1;
            PN[i-1] = true;//cout<<i-1<<endl;
        }
        if(IsPrimeNumber(i+1)){
            PrimeNum[countPN++] = i+1;
            PN[i+1] = true;//cout<<i+1<<endl;
        }
        countPNs = i+1;//cout<<i-1<<" "<<PN[i-1]<<endl;
    }
}
 
bool IsPrimeNumber(long long x){
    //if(x == 2 || x == 3) return true;
    //if(x <= 4 || x%2 == 0 || x%3 == 0)   return false;
    //if(x < countPNs) return PN[x];
    for(long long i = 0; PrimeNum[i] * PrimeNum[i] <= x; i++)
        if(x%PrimeNum[i] == 0)return false;
    return true;
}
 
 
int main(){
    clock_t start, end;
    long long n = true, counta;
    start = clock();
    PrimeN();
//  cout<<PrimeNum[countPN-1]<<" "<<countPNs<<endl;
//  cout<<clock()-start<<"ms"<<endl;
     
    while(cin>>n){
        counta = 1;
         
         
        //cout<<(IsPrimeNumber(n)?"yes":"no")<<endl;
        start = clock();
        //cout<<IsPrimeNumber(n)<<endl;
        for(int i = 1; i <= n; i+=2){
            if(PN[i])counta++;
        //  cout<<i<<" "<<PN[i]<<endl;
        }
        if(n == 1) counta = 0;
        cout<<counta<<endl;
    //  cout<<clock()-start<<"ms"<<endl;
    }
    return 0;

C++: #include <bits/stdc++.h>
using namespace std;

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void init_sieve(vector<bool> &is_prime,int n){
	for(int i=0; i<n; ++i) is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2; i*i<=n; ++i){
		if(is_prime[i]){
			for(int j=2*i; j<n; j+=i) is_prime[j]=false;
		}
	}
}

vector<bool> is_prime(1e6,true);

void solve(int n){
    int ans=0;
    rep(i,0,n+1) if(is_prime[i]) ++ans;
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    init_sieve(is_prime,1e6);
    int n;
    while(cin >> n) solve(n);
    return 0;
}