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 <cstring>
#define STA 1000000
using namespace std;

bool prime[STA];

int main(){
    memset(prime,true,sizeof(prime));
    for(int i=2;i<STA;i++){
        for(int j=2;i*j<STA/2;j++) prime[i*j] = false;
    }
    int n;
    while(cin >> n){
        int cnt = 0;
        for(int i=2;i<=n;i++){
            if(prime[i]) cnt++;
        }
        cout << cnt << endl;
    }
}

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

#define MAX_NUM (1000000)

int main(void)
{
  static bool searchList[MAX_NUM];
  static bool isPrime[MAX_NUM];
  static int primeNum[MAX_NUM];
  
  double maxSq = sqrt((double)(MAX_NUM - 1));
  
  for (int i = 2; i <= maxSq + 1; i++) {
    if (!searchList[i]) {
      isPrime[i] = true;
      for (int j = 2; j < MAX_NUM; j++) {
        if (j % i == 0) {
          searchList[j] = true;
        }
      }
    }
  }
  
  for (int i = maxSq + 2; i < MAX_NUM; i++) {
    if (!searchList[i]) {
      isPrime[i] = true;
    }
  }
  
  
  for (int i = 2; i < MAX_NUM; i++) {
    primeNum[i] = isPrime[i] ? primeNum[i - 1] + 1 : primeNum[i - 1];
  }
  
  int n;
  while (std::cin >> n) {
    std::cout << primeNum[n] << std::endl;
  }
  
  return 0;
}

C++: //
//  main.cpp
//  CppTest
//
//  Created by Ryu on 2017/02/08.
//  Copyright ?? 2017??´ Ryu. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    long in[30];
    long out[30];
    int n = 0;
    long max = 0;
    while(cin >> in[n]){
        if(max < in[n]){
            max = in[n];
        }
        n++;
    }
    //printf("%d", n);
    
    long p[100000];
    p[0] = 2;
    int m = 1;
    for (int i = 3; i <= max; i += 2) {
        bool prime = true;
        for(int j = 0; j < m; j++){
            if (i % p[j] == 0) {
                prime = false;
                break;
            }
            if (i / 5 < p[j]) {
                break;
            }
        }
        if (prime) {
            p[m] = i;
            //printf("%ld\n", p[m]);
            m++;
        }
    }
    
    
    for (int i = 0; i < n; i++) {
        int s = 0;
        while (in[i] >= p[s] && p[s] != 0) {
            //printf("in: %ld, p: %ld\n", in[i], p[s]);
            s++;
        }
        out[i] = s;
        printf("%ld\n", out[i]);
    }
    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}

inline void fast_io(){ios::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple

template<int N>
struct Sieve {
  int F[N];
  vector<int> P;
  Sieve(){}
  void build(){
    iota(F, F + N, 0);
    for (int p = 2; p < N; ++p){
      if (F[p] == p) P.emplace_back(p);
      for (int i = 0; i < P.size() && P[i] <= F[p]; ++i){
        int tmp = P[i] * p;
        if (tmp >= N) break;
        F[tmp] = P[i];
      }
    }
  }
  int count(int l, int r){
    if (l) return count(0, r) - count(0, l);
    return lbnd(P, r);
  }
};

int main()
{
  Sieve<1000000> sieve;
  sieve.build();

  for (int n; ~scanf("%d", &n);){
    printf("%d\n", sieve.count(0, n + 1));
  }

  return 0;
}

C++: #include<cstdio>
#include<cstring>
using namespace std;
const int MAXN=1e7;
int is_prime[MAXN],prime[MAXN];
int main(void){
	memset(is_prime,-1,sizeof(is_prime));
	int index=0;
	prime[0]=prime[1]=0;
	for(int i=2;i<MAXN;i++){
		prime[i]=is_prime[i]?++index:index;
		for(int j=2*i;j<MAXN;j+=i)
		is_prime[j]=0;
	}
	int n;
	while(scanf("%d",&n)!=EOF){
		printf("%d\n",prime[n]);
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int n;
int prime[1000000];
int primesum[1000000];
int result[30];
int datasets;

int main()
{
	prime[0] = 0;
	prime[1] = 0;
	prime[2] = 1;
	primesum[0] = 0;
	primesum[1] = 0;
	primesum[2] = 1;

	cin >> n;
	
	for(int a = 3;a<=n;a++)
	{
		prime[a] = 1;
		for(int b = 2;b<a;b++)
		{
			if(a%b==0)
			{
				prime[a] = 0;
				break;
			}
		}
		primesum[a] = primesum[a-1]+prime[a];
		
	}

	cout << primesum[n] << endl;

	return 0;
}

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

int main(){
	while(1){
		int ans=0;
		int n;
		cin>>n;
		if(cin.eof())break;
		if(n==1){
			cout<<0<<endl;
		}else{
			if(n>=2)ans++;
			if(n>=3)ans++;
			if(n>=4){
				for(int i=4;i<=n;i++){
					bool prime=true;
					for(int k=2;k<=sqrt(i);k++){
						if(i%k==0){
							prime=false;
							break;
						}
					}
					if(prime)ans++;
				}
			}
		cout<<ans<<endl;
		}
	}
}

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

int pri[1000000]={0};


int main(){
	
	pri[0]=pri[1]=1;
	for(int i=2;i*i<=999999;i++){
		for(int j=i*2;pri[i]==0&&j<=999999;j+=i){
			pri[j]=1;
		}
	}
	
	int n;
	while(cin>>n){
		int tmp=0;
		for(int i=0;i<=n;i++){
			if(pri[i]==0)tmp++;
		}
		cout<<tmp<<endl;
	}
	
	return 0;
}

C++: #include <stdio.h>

int isPrime(int x){
  int i;

  if(x == 0 || x == 1) return 0;

  for(i=2;i*i<=x;i++){
    if(x % i == 0){
      return 0;
    }
  }
  return 1;
}

int main(void){
  int i,n;
  int res;

  while(scanf("%d",&n) != EOF){
    res = 0;
    for(i=2;i<=n;i++){
      if(isPrime(i)){
        res++;
      }
    }
    printf("%d\n",res);
  }

  return 0;
}

C++: #include<iostream>

using namespace std;

int main(void){
  int n,prime[1000000],ans[1000000];


  for(int i=0;i<1000000;i++)prime[i]=ans[i]=0;
  prime[0]=prime[1]=1;

  for(int i=2;i*i<1000000;i++)
    if(prime[i]==0)
      for(int j=2*i;j<1000000;j+=i)
	prime[j]=1;
  
  int cnt=0;
  for(int i=0;i<1000000;i++){
    if(prime[i]==0)cnt++;
    ans[i]=cnt;
  }

  while(cin >> n)
    cout << ans[n] << endl;
  
  return 0;
}