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] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := i*2; j < MAX; j+=i {
                                primes[j] = 0
                        }
                }
        }
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>
 
// #include <unordered_set>
// #include <unordered_map>
 
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
 
#define pb push_back
#define mp make_pair
 
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
 
typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;
 
const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
 
using namespace std;
 
#define N 1000000
int arr[N];
int a[N];
 
void eratosthenes(){
    REP(i,N){
        arr[i]=1;
    }
 
    for(int i=2;i<sqrt(N);i++){
        if(arr[i]){
            for(int j=0;i*(j+2)<N;j++){
                arr[i*(j+2)]=0;
            }
        }
    }
    arr[0]=0;
    arr[1]=0;
}
 
signed main(){

    eratosthenes();
    
    int n;
    int count=0;

    while(cin>>n){
        REP(i,n+1){
            if(arr[i]==1)count++;
        }

        cout<<count<<endl;
        count=0;
    }
 
}

C++: #include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

// エラストテネスの篩, o(n)程度
// n以下の素数の数を返す, prime[i]: i番目の素数, is_prime[i]: iが素数であるか
int sieve(int n, int prime[] = nullptr, bool is_prime[] = nullptr){
	bool flag0 = false, flag1 = false;
	if(prime == nullptr){
		flag0 = true; prime = new int[n];
	}
	if(is_prime == nullptr){
		flag1 = true; is_prime = new bool[n + 1];
	}

	int p = 0;
	fill(is_prime, is_prime + n + 1, true);
	is_prime[0] = is_prime[1] = false;

	for(int i = 2; i <= n; i++){
		if(is_prime[i]){
			prime[p++] = i;
			for(int j = 2*i; j <= n; j+=i) is_prime[j] = false;
		}
	}

	if(flag0) delete prime;
	if(flag1) delete is_prime;

	return p;
}

const int MAX_N = (int)1e6;
int prime[MAX_N];
bool is_prime[MAX_N + 1];

int main(void){
	int num = sieve(MAX_N, prime, is_prime);

	int n;
	while(scanf("%d", &n) != EOF){
		cout << upper_bound(prime, prime + num, n) - prime << '\n';
	}

	return 0;
}

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

int main(){
    int n, cnt;
    bool prime[1000000];
    prime[0] = prime[1] = false;
    
    for(int i = 2;i < 100000;i++){
        prime[i] = true;
    }

    while(cin >> n){
        cnt = 0;
        
        for(int i = 2;i <= sqrt(n);i++){
            if(prime[i]){
                for(int j = 2*i;j<= n;j++){
                    if(j%i == 0){
                        prime[j] = false;
                    }
                }
            }
        }
        
        for(int i = 2;i <= n;i++){
            if(prime[i]){
                cnt++;
            }
        }
        
        cout << cnt << endl;
    }

    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int NUM = 1000000;
  bool prime[NUM];
  prime[0] = false;prime[1] = false;
  for(int i=2;i<NUM;i++)prime[i] = true;
  for(int i=2;i*i<NUM;i++)
    for(int k=2;i*k<NUM;k++)
      prime[i*k]=false;
  int n,c=0,i=0;
  for(cin>>n;i<n;i++)if(prime[i])c++;
  cout<<c<<endl;
  return 0; 
}

C++: #include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
bool hurui[1000000];
int main(){
    int n;
    while(scanf("%d",&n) != EOF){
        for(int i = 0;i <= n;i++)
            hurui[i] = true;

        for(int i = 2;i <= (int)sqrt(n);i++) {
            if(!hurui[i])
                continue;
            int m = i * 2;
            while(m <= n) {
                hurui[m] = false;
                m += i;
            }
        }
        int cou = 0;
        for(int i = 2;i <= n;i++) {
            if(hurui[i]) {
                cou++;
            }
        }
        printf("%d\n",cou);
    }
    return 0;
}

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

const int MAX = 1000000;
bool prime[MAX] = { true };
int pcount[MAX];

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

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

int is_prime_f(int n) {
    int i;
    if(n < 2)
        return -1;
    else if(n == 2)
        return 1;

    if(n % 2 == 0)
        return -1;

    for(i = 3; i <= n / i; i += 2)
        if(n % i == 0)
            return -1;
    return 1;
}

unordered_map<int, int> map;

bool is_prime_map(int n) {
    int is_prime = map[n];
    if (is_prime == 0) {
        is_prime = is_prime_f(n);
        map[n] = is_prime;
    }
    return is_prime == 1;
}

int prime_num_count(int max) {
    int count = 0;
    for (int i = 1; i <= max; ++i) {
        if (is_prime_map(i)) {
            count++;
        }
    }
    return count;
}

int main() {
    string str;
    while(getline(cin, str)) {
        cout << prime_num_count(stoi(str.c_str())) << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <math.h>

int prime[1000000];


bool isPrime(int n) {
  int x = (int)sqrt(n);
  for (int i = 3; i <= x; i += 2) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}


void get_prime(int max_num) {
  int primecount = 1;
  prime[2] = primecount;
  for (int i = 3; i <= max_num; i += 2) {
    if (isPrime(i))
      prime[i] = ++primecount;
    else
      prime[i] = primecount;
  }
}


int main () {
  int ns[30];
  int i = 0, max_num;
  while (std::cin >> ns[i]) {
    max_num = std::max(max_num, ns[i]);;
    if (ns[i] % 2 == 0)
      ns[i] --;
    i ++;
  }
  get_prime(max_num);
  for (int j = 0; j < i; j ++) {
    std::cout << prime[ns[j]] << std::endl;
  }
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>

using namespace std;


int main(){

	int i, j, k;
	int n;

	while(cin >> n){

		int count = 0;

		if(n>2){
			count ++;
			for(i=3 ; i<=n ; i+=2){
				for(j=3 ; j<=(int)sqrt(i) ; j+=2){
					k = i % j;
					if(k == 0) break;
				}
				if(j > (int)sqrt(i)) count ++;
			}
		}
		cout << count << endl;

	}


	return 0;
}