Go: package main

// https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)

	for {
		n, err := nextInt()
		if err != nil {
			break
		}
		maybePrime := make([]bool, n+1)
		for i := 0; i <= n; i++ {
			maybePrime[i] = true
		}

		maybePrime[0] = false
		maybePrime[1] = false
		for i := 2; i <= int(math.Sqrt(float64(n)))+1; i++ {
			j := i * 2
			for j <= n {
				maybePrime[j] = false
				j += i
			}
		}

		nPrimes := 0
		for _, p := range maybePrime {
			if p {
				nPrimes++
			}
		}
		// fmt.Println(maybePrime)
		fmt.Println(nPrimes)
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;

// tourist set
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << '\n'; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<'\n'
#define p2(s, t) cout << (s) << " " << (t) << '\n'
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << '\n'
#define p_yes() p("YES")
#define p_no() p("NO")
#define SZ(x) ((int)(x).size())
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(ALL(A), greater<ll>())

void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}

const ll mod = 1e9 + 7;
const ll inf = 1e18;
const double PI = acos(-1);

const int N_MAX = 1e7 + 10;
bool is_prime[N_MAX];

// エラトステネスのふるい
void Eratosthenes(){
    FOR(i, 0, N_MAX){
        is_prime[i] = true;
    }
    is_prime[0] = false;
    is_prime[1] = false;
    for(ll i=2; i*i<=N_MAX; i++){
        if(is_prime[i]){
            int p = i;
            int step_p = p;
            // それの倍数を消していく
            while(p < N_MAX){
                p += step_p;
                if(p<N_MAX){
                    is_prime[p] = 0;
                }
            }
        }
    }
}

ll f(ll n){
  ll cnt=0;
  FOR(i, 2, n+1){
    if(is_prime[i]) cnt++;
  }
  return cnt;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll N; 
    Eratosthenes();

    while(cin>>N){
      ll ans = f(N);
      p(ans);
    }
    
    return 0;
}

C++: #include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int main(void){
  const int n = 1000000;
  bool* check_A = (bool*)malloc(sizeof(bool)*n);
  int*  num_A   = (int*)malloc(sizeof(int)*n);
  int N = 0, temp = 2;
  memset(check_A, true, n);
  check_A[0] = false;
  check_A[1] = false;
  num_A[0] = 0;
  num_A[1] = 0;
  for(int i = 0; i < n; i++){
    if(check_A[i]){
      for(;temp < i;temp++){
	num_A[temp] = N;
      }
      temp++;
      num_A[i] = ++N;
      for(int j = 2; i*j < n; j++){
	check_A[i*j] = false;
      }
    }
  }
  int s;
  while(cin >> s){
    cout << num_A[s] << endl;
  }
  return 0;
}

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

int main(){

int i,j,n,count;

/**while(**/scanf("%d",&n);// != EOF){

count=2;

if(n<5){
	count=n-1;
}else{
	for(i=5;i<n+1;i+=2){
		for(j=2;j<(int)sqrt(i)+1;j++)

			if(i%j==0){
				break;
			}else if(j==(int)sqrt(i))
				count+=1;
	}
}

printf("%d\n",count);

//}
return 0;		
}

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 l[999999]={0};
	int r=0,n;
	for(int i=0;i<999999;i++){
		if(isprime(i+1)){
			r++;
			l[i]=r;
		}
	}
	while(scanf("%d",&n)!=EOF){
		printf("%d\n",l[n-1]);
	}
	return 0;
}

C++: #include <stdio.h>
const int MAX_V = 1000000;
int prime[MAX_V+1];
int sum;
int main(){
 int i, k, v, n, left, right;
 while(scanf("%d", &n) != EOF) { 
 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;
   }
  }
 }
 sum= 0; 
 for(i= 0; i <= n; i++){
  sum = sum + prime[i];
 }
 printf("%d\n", sum);
 }
 return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int a,b,c=0;
	int flg=0;
	while(cin>>a){
		for (int A=2;A<=a;A++){
		flg=0;
			for (int B=2;B<=A;B++){
				b=A%B;
				if (A==B){
					c++;
					break;
				}
				if (b==0) break;
			}
		}
		cout<<c<<endl;
		c=0;
		a=0;
	}
	return 0;
}

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

int main(){
  bool a[1000000];

  a[0]=a[1]=false;
  for(int i=2;i<1000000;i++){
    a[i]=true;
  }

  for(int i=2;i*i<1000000;i++){
    if(a[i]){
      for(int j=i*i;j<10000000;j+=i){
        a[j]=false;
      }
    }
  }

  int n[1000000];

  int tmp=0;
  for(int i=0;i<1000000;i++){
    if(a[i]){
      tmp++;
    }
    n[i]=tmp;
  }

  while(true){
    int m;
    cin>>m;

    if(cin.eof()){
      break;
    }
    
    cout<<n[m]<<endl;

  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){

  int n;

  while(cin>>n){

	int cnt=0;
	
	if(n <= 1){
	  cout<<0<<endl;
	  continue;
	}

	else
	  cnt++;
	
	for(int i=3;i<=n;i+=2){
	  int f = true;
	  for(int j=3;j<i;j+=2){
		if(i%j==0){
		  f = false;
		  break;
		}
	  }
	  if(f == true)
		cnt++;
	}

	cout<<cnt<<endl;
	
  }

  return 0;
  
}