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++: #pragma GCC optimize "O3"
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define REP_FROM(i,m,n) for (int i = (m); (i) < int(n); ++(i))
#define REP_REV(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define REP_FROMREV(i,m,n) for (int i = (n)-1; (i) >= int(m); --(i))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#ifndef LOCAL
#define cerr if (false) cerr
#endif
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }
template <class T> T sq(T x) { return x * x; }
template <class T> T clamp(T a, T l, T r) { return min(max(a, l), r); } // [l, r]
const double EPS = 1e-10;
const double PI  = acos(-1.0);

vector<bool> ptable;

void sieve(LL max) {
	if(max+1 > ptable.size())
		ptable.resize(max+1, true);

	ptable[0] = ptable[1] = false;

	for(LL i = 2; i*i <= max; i++)
		if(ptable[i])
			for(LL j = 2; i*j <= max; j++)
				ptable[i*j] = false;
}

int main(int argc, char *argv[]) {
	// Something to do
	sieve(1000000);
	int n;
	while(cin >> n) {
		int cnt = count(ptable.begin(), ptable.begin()+n+1, true);
		cout << cnt << endl;
	}
	return 0;
}

C++: #include <iostream>

int main() {
	int input;
	// ??\???????????°????????????????????????????????????
	while (std::cin >> input) {
	int count = 0;
	for (; input > 1; input--) {
		bool fl = true;
		for (int i = 2; fl == true, i < input; i++)
			if (!(input % i))
				fl = false;

		if (fl)
			count++;
	}

			std::cout << count << std::endl;
	}
}

C++: /***********************************************************
エストラテネスの篩
O(n log n)よりははやい.
 ***********************************************************/

#include <vector>

std::vector<bool> prime_table(int N){
    std::vector<bool> is_prime(N + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i * i <= N; i++){
        if (is_prime[i]){
            for (int j = i * 2; j <= N; j += i) is_prime[j] = false;
        }
    }
    return is_prime;
}

std::vector<int> compute_primes(int N){
    std::vector<bool> is_prime = prime_table(N);
    std::vector<int> primes;
    for (int i = 0; i < N + 1; i++) if (is_prime[i]) primes.push_back(i);
    return primes;
}


// solution for http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009&lang=jp

#include <vector>
#include <iostream>

using namespace std;

int main(){
    int n;
    while(cin >> n){
        vector<int> primes = compute_primes(n);
        cout << primes.size() << endl;
    }
    return 0;
}

C++: #include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
    int x;
    int i, j;
    int p[999999] = {};
    p[2] = 1;
    for (i = 3; i < 1000000; i++) {
        for (j = 2; ; j++) {
            if (!(i % j)) {
                break;
            } else if (j > sqrt(i)) {
                p[i] = 1;
                break;
            }
        }
    }
    while (scanf("%d", &x) != EOF) {
        j = 0;
        for (i = 0; i <= x; i++) {
            j += p[i];   
        }
        printf("%d\n", j);
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<int> prime_list;
  bool flag;

  prime_list.push_back(2);
  for (int i = 3; i < 50; i++) {
    for (int j = 0; j < prime_list.size(); j++) {
      if(i%prime_list[j] == 0) {
        flag = false;
        break;
      } else {
        flag = true;
      }
    }
    if (flag) {
      prime_list.push_back(i);
    }
  }

  int data, count;
  while(cin >> data) {
    for (int i = 0; i < prime_list.size() && prime_list[i] < data; i++, count = i);
    cout << count << endl;
  }
}

C++: #include <stdio.h>
#include <string.h>
int main(void){
    int n=999999,a,b,c;
    short x[1000000];
    memset(x,0,sizeof(x));
    for(a=2,c=0;a<=n;a++){
        if(x[a]){x[a]=c;continue;}
        x[a]=++c;
        for(b=a*2;b<=n;b+=a)x[b]=-1;
    }
    while(~scanf("%d",&n)){
        printf("%d\n",x[n]);
    }
    return 0;
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int prime[1000000];
int main(){
    int n,ans=0;
    for(int i=0;i<1000000;i++)
        prime[i]=1;
    prime[1]=0;
    prime[2]=1;
    for(int i=1;i<1001;i++){
        if(prime[i]==1){
            for(int j=i+1;j<1000000;j++){
                if(j%i==0)
                    prime[j]=0;
            }
        }
    }
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        if(prime[i]==1)
        ans++;
    }
    printf("%d",ans);
    return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <vector>
#define pb push_back
using namespace std;

int primes(int n) {
  int cnt=0;
  vector<bool> pri(n+1,false);
  for(int i=2;i<=n;i++) {
    if(pri[i]==false) {
      cnt++; pri[i]=true;
      for(int j=i*2;j<=n;j+=i) {
	pri[j]=true;
      }
    }
  }
  return cnt;
}


main() {
  int n;
  while(cin>>n) {
    cout << primes(n) << endl;
  }
}