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<cstdio>
using namespace std;
const int N = 1000000;

int main(){

  int IsPrime[N];
  IsPrime[0] = -1;
  IsPrime[1] = -1;
  for(int i=2; i*i<=N;i++){
    if(IsPrime[i]==0){
      IsPrime[i] = 1;
      for(int j=2*i; j<=N; j+=i)
        IsPrime[j] = -1;
      }
  }
  int max;
  while(~scanf("%d",&max)){
    int count=0;
    for(int i=1; i<max+1; i++)
      if(IsPrime[i]==1) count++;
    printf("%d\n",count);
  }
}

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

using namespace std;
int sieve[1000005]= {0}, n, i, j, cnt=0;;
int main()
{
    while(cin>>n)
    {
        cnt=0;
        for(i=2; i<=n+2; i++)
        {
            if(!sieve[i])
            {
                for(j=2*i; j<=n+1; j+=i)
                {
                    sieve[j]=1;
                }
            }
        }

        for(i=2; i<=n; i++)
        {
            if(!sieve[i])
            {
                cnt++;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

template<typename V>
void eratosthenes(V &v) {
  v[0] = v[1] = false;
  loop(i, 2, v.size()) v[i] = true;
  for (int i = 2; i * i < v.size(); i++) {
    if (v[i]) {
      for (int j = i * 2; j < v.size(); j += i) {
        v[j] = false;
      }
    }
  }
}

void solve() {
  vi v(1000000);
  eratosthenes(v);
  loop(i, 1, v.size()) v[i] += v[i - 1];
  int n;
  while (cin >> n) cout << v[n] << endl;
}

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

int main() {
	int n;
	while(cin >> n && n != EOF) {
		bool* prime = new bool[n+1];
		int count = 0;
		for(int i = 2; i < n; ++i) {
			prime[i] = true;
		}
		prime[0] = prime[1] = false;
		
		for(int i = 0; i < n; ++i) {
			if(prime[i]) {
				count++;
				for(int j = 2 * i; j < n; j += i) {
					prime[j] = false;
				}
			}
		}
		
		cout << count << endl;
		delete[] prime;
	}
}

C++: //0009 Prime Number
//100¢Ì³Ì®nªüÍ³ê½Æ«AnÈºÌfª¢­ç é©oÍ·évOðì¬¹æ
//s²ÆÉêÂÌ®nªüÁÄ¢é@EOFªüÍÌIíèÅ é

#include<iostream>
#include<bitset>
using namespace std;

int main(void)
{
	const int N = 1000000;	//100ÂmÛ
	bitset<N> isPrime;
	int n;
	int i, j;

	while( cin >> n)
	{
		//â¿ðg¢Ü·
		isPrime.set();
		isPrime[0] = isPrime[1] = false;
		for(i = 2; i <= n; i++)
		{
			if(isPrime[i])
			{
				for(j = 2*i; j <= n; j+=i)
				{
					isPrime[j] = false;
				}
			}
		}

		int count = 0;
		for(i = 0; i <= n; i++)
			if(isPrime[i])
				count++;

		cout << count << endl;
	}
	return 0;
}

C++: #include <iostream>

int main() {
	// Prime Data Set
	char p[1000000] = {0};
	p[1] = 1;
	for( int i=2; i<1000; i++) if(!p[i]) for( int j=i+i; j<1000000; j+=i) p[j] = 1;
	
	int n;
	int sum;
	while( std::cin >> n) {
		sum = 0;
		for( int i=1; i<n; i++) {
			if(!p[i]) sum++;
		}
		std::cout << sum << std::endl;
	}
}

C++: 
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#define INF 100000
using namespace std;
typedef long long int ll;

int main(){
    vector<ll> era(10000000,0);
    for (int i=1; i<era.size(); i++) {
        era[i]=i;
    }
    for (int i=2; i<era.size(); i++) {
        if (era[i]!=0) {
            ll q = i + era[i];
            while (q<era.size()) {
                era[q]=0;
                q += era[i];
            }
        }
    }
    int n;
    while (cin >> n) {
        int ans=-1;
        for (int i=1; i<=n; i++) {
            if (era[i]==i) {
                ans++;
            }
        }
        cout << ans <<endl;
    }
}

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

int main(){

	const int N_MAX=1000000;
	int i,j,n[32],ni,max;
	int count[N_MAX];
	bool so[N_MAX];
	
	for(i=0;i<N_MAX;i++)
		so[i]=true;
	ni=0;
	max=0;
	while(cin>>n[ni])
		if(n[ni++]>max)
			max=n[ni-1];
	so[0]=so[1]=0;
	for(soi=0,i=2;i<=1000;i++){
		if(so[i]==0)continue;
		for(j=i*2;j<=max;j+=i)
			so[j]=false;
	}
	for(i=2;i<=max;i++){
		count[i] = count[i-1]+so[i];
	}
	for(i=0;i<ni;i++)
		cout << count[n[i]] << endl;

	return 0;
}

C++: #include<cstdio>

long prim[1000100];
long prima[1000100];
    
int main() {
    long n, i, x = 0;
    for (i = 2; i <= 1000000; i++) {
        prim[i] = i;
    }
    for (i = 2; i <= 1000000; i++) {
        if (prim[i] != 0) {
                  prima[x] = prim[i];
                  x+= 1;
                  int j = i;
                  while ( j <= 1000000) {
                        prim[j] = 0;
                        j+= i;
                  }
        }
    }
    while (scanf("%ld", &n) != EOF) {
          long a = 0;
          while ( prima[a] <= n) {
                a++;
          }
          printf("%ld\n", a);
    }
    return 0;
}