Go: package main

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

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[n])
    }
}

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;
}

C++: #include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
  long long int a[1000000]={0};
  a[1]=1;
  for(int i=2;i<sqrt(1000000);i++){
    for(int j=2;j<sqrt(1000000);j++){     
      a[i*j]=1;
    }
  }
  int n;
  int cont;
  while(scanf("%d",&n)!=EOF){
    cont=0;
    for(int i=1;i<=n;i++){
      if(a[i]==0)cont++;
    }
    cout<<cont<<endl;
  }
}

C++: #include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

const int size=1000000;
vector<int> map(size,1);
void sieve(int p)
{
    for(int j=p*2;j<size;j+=p)
    {
        map[j]=0;
    }
}
int main(void)
{
    map[0]=0;
    map[1]=0;
    sieve(2);
    sieve(3);
    sieve(5);
    for(int i=7;i<1000;i+=6)
    {
        sieve(i);
        sieve(i+4);
    }

    while(1)
    {
        int n;
        int num=scanf("%d",&n);
        if(num != 1)
            break;
        printf("%d\n",count(map.begin(),map.begin()+n+1,1));
    }
    return 0;
}

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


vector<int> sieve_of_eratosthenes(int n) {
  vector<int> primes(n);
  for (int i = 2; i < n; ++i)
    primes[i] = i;
  for (int i = 2; i*i < n; ++i)
    if (primes[i])
      for (int j = i*i; j < n; j+=i)
        primes[j] = 0;
  return primes;
}

int main()
{
	int n;
	while(cin>>n){
		vector<int> V=sieve_of_eratosthenes(n+1);
		V.erase(remove(V.begin(),V.end(),0),V.end());
		cout<<V.size()<<endl;
	}
	return 0;
}

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

C++: #include<stdio.h>
#include<math.h>
int isprime(int x){
	int i;
	if(x == 2){
 		return 1;
	}
  	if(x<2||x%2==0){
		return 0;
	}
	i = 3;
	while( i <= sqrt(x) ){
		if(x%i==0){
			return 0;
		}
		i = i + 2;
	}
	return 1;
}
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		int c=0;
		for(int i=0;i<=n;i++){
			if(isprime(i)){
				c++;
			}
		}
		printf("%d\n",c);
	}
	return 0;
}