Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func check(n int) int {
	eratos := make([]bool, n+1)
	cnt := 0
	for i := 2; i < len(eratos); i++ {
		if !eratos[i] {
			cnt++
			for j := i*i; j < len(eratos); j += i {
				eratos[j] = true
			}
		}
	}
	return cnt
}

func main() {
	for scanner.Scan() {
		n := nextInt()
		fmt.Println(check(n))
	}
}

C++: //AOJ 0009 Prime Number
//2016.6.25
//Algorithm:Prime
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;

const int maxn=1000006;
bool prime[maxn];
int n;
int cnt[maxn];

int main()
{
	for(int i=1;i<maxn;i++)
		prime[i]=true;
	prime[1]=false;
	for(int i=2;i<maxn;i++)
		if(prime[i])
			for(int j=i*2;j<maxn;j+=i)
				prime[j]=false;
	for(int i=1;i<maxn;i++)
		cnt[i]=cnt[i-1]+prime[i];
	while(cin>>n)
	{
		cout<<cnt[n]<<endl;
	}
	return 0;
}

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

const int C = (int)1e8;

bool isprime[C];
int prime[C];

void init() {
  fill(isprime, isprime+C, true);
  isprime[0] = isprime[1] = false;
  for (auto i=2; i<C; i++) {
    if (isprime[i]) {
      for (auto j=2; i*j<C; j++) {
	isprime[i*j] = false;
      }
    }
  }
  prime[0] = 0;
  for(auto i=1; i<C; i++) {
    prime[i] = ((isprime[i]) ? prime[i-1]+1 : prime[i-1]);
  }
}

int main() {
  init();
  int n;
  while (cin >> n) {
    cout << prime[n] << endl;
  } 
}

C++: #include <stdio.h>

const int MAX_V = 100000;
int prime[MAX_V+1];

void init(){
    int i, k, v;
    for(i=2; i<=MAX_V; i++){
        prime[i] = 1;
    }
    for(i=2; i*i<=MAX_V; i++){
        if(prime[i]){
            for(k=2*i; k<=MAX_V; k+=i){
                prime[k]=0;
            }
        }
    }   
}

int isprime(int n){
    return prime[n];
}

int main(){
    init();
    int num;
    while(scanf("%d", &num) != EOF){
        int count=0;
        for(int i=2; i<=num; i++){
            if(isprime(i)==1)
                count++;
        }
    printf("%d\n", count);
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
long n,i,j,*nn;
for(;;){
cin>>n;
if(cin.eof())break;
nn=new long [n+1];
nn[1]=0;nn[2]=1;
for(i=3;i<=n;i+=2)nn[i]=1;
for(i=4;i<=n;i+=2)nn[i]=0;
for(i=3;i*i<n;){
for(j=i;i*j<=n;j+=2)nn[i*j]=0;
i++;while(nn[i]=0)i++;
}
for(i=2,j=0;i<=n;i++)if(nn[i]==1)j++;
cout<<j<<endl;
delete [] nn;
}
return 0;
}

C++: #include <iostream>
#include <string>
#include <cctype>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map> // pair
#include <set>
#include <string>

#define MAXSIZE 200000
#define PI 3.141592653589
using namespace std;

template<typename T>
T add(T a,T b){
  return a+b;
}

namespace A
{
  int f(void){
    return 1;
  }
}

int main(){
  int n;
  while (std::cin >> n) {
    int count=0;//素数の数
    for(int i=2;i<=n;i++){
      int flag=0;
      for(int j=2;j<=sqrt(i);j++){
        if(i%j==0){
          flag=1;
          break;
        }
      }
      if(flag==0){
        count++;
      }
    }
    std::cout << count << '\n';
  }

}

C++: #include<iostream>
#include<math.h>
using namespace std;
bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; 

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
            return false;
    }
    return true;
}
int main() {
  int n;
  while(cin>>n) {
    int count=0;
    for(int i=1;i<=n;i++){
      if(IsPrime(i))
	count++;
    }
    cout<<count<<endl; 
 }
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
using namespace std;
typedef pair<int,int> P;
const int INF = (int)((unsigned int)-1>>1);


int main(){
    vector<int> prime;
    prime.push_back(2);

    for(int i=3;i<=999999;i+=2){
        bool is_prime = true;
        for(int j=0;j<prime.size();j++){
            if (prime[j]*prime[j] > i) break;
            if (i % prime[j] == 0){
                is_prime = false;
                break;
            }
        }
        if(is_prime){
            prime.push_back(i);
        }
    }

    int n;
    while(cin >> n){
        int ans = 0;
        for(int j=0;j<prime.size();j++){
            if (prime[j] > n) break;
            ans++;
        }
        cout << ans << endl;
    }

    return 0;
}

C++: //C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#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 <ctime>
#include <string>
using namespace std;

typedef long long ll;
/*
bool is_prime(int n){
    for (int i = 2; i*i<=n;i++){
        if(n%i==0) return false;
    }
    return n!=1;
}
*/
vector<int> divisor(int n){
    vector<int> res;
    for( int i=1;i*i<n;i++){
        if(n%i==0){
            res.push_back(i);
            if(i!=n/i)res.push_back(n/i);
        }
        
    }
    return res;
}
map<int,int> prime_factor(int n){
    map<int,int> res;
    for(int i=2;i*i;i++){
        if(n%i==0){
            res[i]++;
            n=n/i;
        }
    }
    if(n!=1)res[n]=1;
}


const ll MAX_N=1000000;
//ll prime[MAX_N];
bool is_prime[MAX_N];

int sieve(int n){
    
    ll p=0;
    for(ll i=0;i<=n;i++) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(ll i=2;i<=n;i++){
        if(is_prime[i]){
            //prime[p++]=i;
            p++;
            for(ll j=i*2;j<=n;j+=i){
                is_prime[j]=false;
            }
        }
    }
    return p;
}

int main(){
    ll a;
    while(scanf("%lld", &a)!=EOF){
        cout<<sieve(a)<<endl;
    }
    return 0;}

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

/*
1???2 ?????? n ?????§?????´??°???????????????
2??????????????£???????????°????????§???????°?????????????????????? p ??¨?????????????????????????????????????????°?????? p ??¨?????????
	p ??\?????? p ????????°?????¨????¶????????????????
3???2??????????????°?????????????????????p ??? ???n ????¶??????????????????????????????????????????£?????????????´???°???
*/
// ??¨????????????????????????
int SieveOfEratosthenes(int num){
	// num???????´???°?????°
	int count = 0;
	
	// Route Num?????´??°??¨??????????????????
	int routeN_int = (int)sqrt(num);
	//cout << routeN_int << endl;
	
	// ???n?????§?????´??°?????????????´???°????????°????????????
	vector<bool> prime_flag_set(num + 1, true);
	
	for(int i = 0; i < prime_flag_set.size(); i++){
		//cout << "Flag" << i << " " << prime_flag_set[i] << endl;
	}
	cout << endl;
	// 1???2 ?????? n ?????§?????´??°????????????p????????°????????? = false
	for(int p = 2; p < prime_flag_set.size(); p++){
		if( prime_flag_set[p] == false){
			continue;
		}
		int j = 2;
		// 3???2??????????????°?????????????????????p ??? ???n ????¶????????????????
		while(p < routeN_int){
			if(p*j > num+1){
				// num??\???
				break;
			}
			prime_flag_set[p * j] = false;
			//p????????°????±???????
			j++;
		}
	}
	// 2??\???
	for(int i = 2; i < prime_flag_set.size(); i++){
		if(prime_flag_set[i] == true){
			count++;
		};
		//cout << "Flag" << i << " " << prime_flag_set[i] << endl;
	}
	
	return count;
}

int main(){
	int num = 0;
	while(cin >> num){
		cout << SieveOfEratosthenes(num) << endl;
	}
	return 0;
}