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++: #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

struct IsPrime {
 public:
  explicit IsPrime(int max);
  bool operator()(int n);

 private:
  std::vector<bool> is_prime;
};

IsPrime::IsPrime(int max) : is_prime(max + 1, true) {
  is_prime[0] = false;
  is_prime[1] = false;
  for (auto i = 2; i <= std::sqrt(max); i++) {
    if (!is_prime[i]) {
      continue;
    }

    for (auto mult = 2 * i; mult <= max; mult += i) {
      is_prime[mult] = false;
    }
  }
}

bool IsPrime::operator()(int n) { return is_prime[n]; }

int CountPrime(IsPrime& is_prime, int upto) {
  int cnt = 0;
  for (int i = 2; i <= upto; i++) {
    if (is_prime(i)) {
      cnt++;
    }
  }
  return cnt;
}

int main(void) {
  std::vector<int> inputs;
  int n;
  while (std::cin >> n) {
    inputs.push_back(n);
  }

  int max = *std::max_element(inputs.begin(), inputs.end());
  IsPrime is_prime{max};

  for (auto n : inputs) {
    std::cout << CountPrime(is_prime, n) << '\n';
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <math.h>
using namespace std;

bool testinPrimeSet(int num, vector<int> & pset) {
	for (vector<int>::iterator it = pset.begin(); it < pset.end() && sqrt(num) >= (*it); it++) {
		if ((num % (*it) == 0))
			return false;
	}
	return true;
}

int CountPrime(int num, vector<int> & pset) {
	int be = pset.at(pset.size() - 1);
	while (++be <= num) {
		if(testinPrimeSet(be, pset))
			pset.push_back(be);
	}
	return 0;
}

int getdst(int num, vector<int> & pset) {
	int i = 0;
	for (vector<int>::iterator it = pset.begin(); it < pset.end(); it++)
		if ((*it) <= num)
			i++;
		else
			break;
	return i;
}

int main() {
	int n = 0;
	int a[5] = { 2,3,5,7,11 };
	vector<int> dst;
	vector<int> primeset(a, a + 5);
	while (cin >> n) {
		CountPrime(n, primeset);
		dst.push_back(n);
	}
	for (vector<int>::iterator it = dst.begin(); it < dst.end(); it++)
		cout << getdst(*it, primeset) << endl;
	return 0;
}

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

int sieve(int n) {
    if (n <= 1) return 0;
    vector<bool> is_prime(n+1, true);
    is_prime[0] = is_prime[1] = false;

    int res = 0;
    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            res++;
            for (int j = i+i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
    return res;
}

int main() {
    while (1) {
        int n;
        int ret = scanf("%d", &n);
        if (ret < 0) break;
        printf("%d\n", sieve(n));
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int a[1000000];
void sive()
{
    int i,j;
    a[0]=a[1]=1;
    for(i=4;i<=1000000;i+=2) a[i]=1;
    for(i=3;i<=1000;i+=2){
        if(a[i]==0)
        {
            for(j=i*i;j<=1000000;j+=2*i) a[j]=1;
        }
    }
}
int main()
{
    sive();
    int n,i,j=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        if(a[i]==0) j++;
    }
    cout<<j<<endl;

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 0x3f3f3f3f
#define inff -30000000
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
const int MAX=1e6+10;
int prime[MAX];
bool notprime[MAX];
int num=0;
void init(){
    memset(notprime,0,sizeof(notprime));
    for(int i=2;i*i<=MAX;i++){
        if(!notprime[i]){
            prime[num++]=i;
            for(int j=i*i;j<=MAX;j+=i)
                notprime[j]=1;
        }
    }
}
int main(){
    #ifdef SIYU
    freopen("in.txt","r",stdin);
    #endif // SIYU
    int n;
    init();
    while(cin>>n){
        //int *p=upper_bound(prime,prime+num,n);
        //int ans=p-prime;
        //cout<<ans<<endl;
        int ans=0;
        for(int i=0;i<num;i++){
            if(prime[i]<=n)
                ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #pragma  warning (disable:4996)
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#define MAX 1000000
using namespace std;
int amount[MAX];
int vis[MAX];
int prime[MAX];
int main(){
	memset(vis, 0, sizeof(vis));
	memset(prime, 0, sizeof(prime));
	prime[0] = prime[1] = 0;
	int n;
	cin >> n;
	for (int i = 2; i <= n; i++){
		if (!vis[i]){

			prime[i] = 1;
			for (int j = i + i; j <= n; j += i){
				vis[j] = 1;
				prime[j] = 0;

			}
		}
	}
	int sum = 0;
	for (int i = 2; i <= n; i++){
			if (prime[i]){
				sum++;
			}
		}
		cout << sum << endl;
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(int argv,char* argv[]){
unsigned x[30];
int count=0;
for(int i=0;i<argv;I++){
cin>>x[i];
}
for(int i=0;i<argv;i++){
for(int j=1;j<x[i];j++){
if(x[i]%j!=0)
count++;
}
cout<<count<<endl;
count=0;
}
return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long

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

	return 0;
}

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

int main()
{
    int n;
    
    while(cin>>n){
        bool p[n+1];
        int cnt = 0;
        for(int i=0; i<=n; i++){
            if(i==0){
                p[0] = false;
            }
            else if(i==1){
                p[i] = false;
            }
            else if(i==2){
                p[i] = 2;
            }
            else if(i==3){
                p[i] = 3;
            }
            else if(i==5){
                p[i] = 5;
            }
            else if(i==7){
                p[i] = 7;
            }
            else if((i%2!=0)&&(i%3!=0)&&(i%5!=0)&&(i%7!=0)){
                p[i] = true;
            }
            else{
                p[i] = false;
            }
        }
        
        for(int j=0; j<=n; j++){
            if(p[j]==true){
                cnt++;
            }
        }
        
        cout << cnt << endl;
            
    }
    
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 1000000+10;
const int maxn=100000+5;
int prime[maxn];
bool p[MAXN];
int cnt=0;
void getPrime()
{
    memset(p,true,sizeof(p));
    p[0]=p[1]=false;
    for(int i=2;i<=MAXN;i++)
       if(p[i]) {
       	prime[cnt++]=i;
       	for(int j=i*i;j<=MAXN;j+=i)
       	    p[j]=false;
	   }
}
int main()
{
	getPrime();
	/*int k=lower_bound(prime,prime+cnt,999999)-prime;
	for(int i=k;i>=0;i--)
	   if(prime[i]<999999) {
	   	printf("%d\n",i+1);
	   	break;
	   }*/
	for(int i=0;i<cnt;i++)
	   cout<<prime[i]<<" ";
	int n;
	while(scanf("%d",&n)==1){
		int k=lower_bound(prime,prime+cnt,n)-prime;
		if(prime[k]==n) k++;
		printf("%d\n",k);
	}
	return 0;
}