Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		input := nextInt()
		fmt.Println(IsPrime(input))
	}
}

func IsPrime(num int) int {
	eratos := make([]bool, num+1)
	c := 0
	for i := 2; i < len(eratos); i++ {
		if eratos[i] == false {
			c++
			eratosCalc(i, eratos)
		}
	}
	return c
}

func eratosCalc(primeNum int, eratos []bool) {
	for i := primeNum * primeNum; i < len(eratos); i += primeNum {
		eratos[i] = true
	}
}

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

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

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#define FOR(i, a, b)  for(int i=a; i<b; ++i)
#define rFOR(i, a, b) for(int i=a-1; i>=b; --i)
#define REP(i, n) for(int i=0; i<n; ++i)
#define rREP(i, n) for(int i=n-1; i>=0; --i)
#define all(a)  a.begin(), a.end()
#define MAXNUM 1000000
using namespace std;

int num[MAXNUM]={0};

int main(){
  int n;
  while(cin >> n){
    vector<int> vec;
    vec.push_back(2);
    for(int i = 3; i<=n; i+=2){
      if(num[i]==1) continue;
      FOR(j, 2, MAXNUM){
        if(i*j>n)  break;
        num[i*j]=1;
      }
      vec.push_back(i);
    }
    cout << vec.size() << endl;
  }
  return 0;
}

C++: 
#include <cstdio>
#include <iostream>
using namespace std;
int list[1000000],p[80000];
int sum[1000000];

void gets()
{
    p[0]=2;
    int key=0;
    for(int i=0;i<1000000;i++)
        list[i]=i%2;
    for(int i=3;i<1000000;i+=2)
        if(list[i])
    {
        p[++key]=i;
        for(int j=2*i;j<1000000;j++)
            list[j]=0;
    }
}

int main()
{
    gets();
    for(int i=0;i<1000000;i++)
        sum[i]=0;
    for(int i=0;i<80000;i++)
        sum[p[i]]=1;
    for(int i=1;i<1000000;i++)
        sum[i]+=sum[i-1];
    int n;
    while(cin>>n)
        cout<<sum[n]<<endl;
    return 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;
		}
	}
}