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

using namespace std;

int main() {
	static bool cmp[1000000] = { true };
	static int npr[1000000];
	for (int i = 2; i<1000000; i++) {
		if (!cmp[i]) {
			for (int j = 2; j*i<1000000; j++) {
				cmp[i*j] = true;
			}
		}
		npr[i] = npr[i - 1] + !cmp[i];
	}
	for (int n; cin >> n; n++) {
		cout << npr[n] << endl;
	}
	return 0;
}

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

#define Max 1000000

int prime [10000000];

int main()
{
	int n, out;

	for (int i = 2; i * i < Max; i++){
		if (prime[i] == 0){
			for (int j = i; j < Max; j += i){
				if (!(j == i)) prime[j] = 1;
			}
		}
	}

	while (cin >> n){
		out = 0;
		for (int i = 0; i <= n; i++){
			if (prime[i] == 0) out++;
		}
		cout << out - 2 << endl;
	}
	return(0);
}

C++: #include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
int main()
{
	int k, n, s, t, i = 0, j, maxV = INT_MIN, A[30] = {};
	while (cin >> k) {
		A[i++] = k;
		if (maxV < k)
			maxV = k;
	}
	s = maxV + 1;
	vector<long> vP(s, 0);
	int c = 0;
	for (k = 2; k < s; ++k){
		if (vP[k] == 0)
			vP[k] = ++c;
		t = (s - 1) / k;
		for (j = 2; j <= t; ++j)
			vP[j * k] = -1;
	}
	for (j = 0; j < i; ++j){
		k = vP[A[j]];
		if (1 == A[j])
			k = 0;
		else if(-1 == k)
			while (-1 == (k = vP[--A[j]])){}
		cout << k << "\n";
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <set>
#include <functional>

class Mod{
		const int n;
		public:
			Mod(const int _n):n(_n){}
			bool operator()(const int _src)const{
				return ! (_src % n);
			}
	};

const std::vector<int> Eratosthenes(const std::vector<int> src){
	std::vector<int> result,tmp(src);
	while(!tmp.empty()){
		int n(tmp[0]);
		result.push_back(n);
		Mod mod(n);
		std::vector<int>::iterator it= std::remove_if( tmp.begin(), tmp.end(), mod );
		tmp.erase(it,tmp.end());
	}
	return result;
}

int main(int,char**){
	int n;
	while(std::cin >>n){
		std::vector<int> vec;
		vec.reserve(n);
		for(int i(2);i<=n;++i)
			vec.push_back(i);
		std::vector<int> primes= Eratosthenes(vec);
		std::cout << primes.size() <<std::endl;
	}
	return 0;
}

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

int pn[1000002];

int main(){
int n, Count;
cin.tie(0);
while(scanf("%d",&n)!=EOF){
Count=0;
memset(pn,0,sizeof(pn));
pn[0]=pn[1]=1;
for(int i=2;i<=n;i++) if(!pn[i]) for(int j=1;i*j<=n;j++) pn[i*j]=1;
for(int i=2;i<=n;i++) if(!pn[i]) Count++;
cout<<Count<<endl;
}
return 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;

#ifndef SIEVE
#define SIEVE
// エラストテネスの篩, 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;
}
#endif

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

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

    // for(int i = 0; i < 30; i++) printf("prime[%d] = %d\n", i, prime[i]);
    // for(int i = 1; i < N; i++){
    //     res[i] = res[i-1] + is_prime[i];
    // }

    int n;

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

    return 0;
}

C++: #include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
#define INF 1<<20

struct edge{
	int to;
	int cost;
	edge() {};
	edge(int a, int b) {
		to = a;
		cost = b;
	}
};

struct Node {
	int pos;
	int cost;
	Node() {};
	Node(int a, int b) {
		pos = a;
		cost = b;
	}
	bool operator <(const Node& rhs) const {
		return cost > rhs.cost;
	}
};

void dijkistra(int st, int TO,int V,vector<vector<edge> > graph) {
	priority_queue<Node> q;
	vector<int> d(V);
	for (int i = 0;i < V;i++) {
		d[i] = INF;
	}
	d[st] = 0;
	q.push(Node(st, 0));
	while (!q.empty()) {
		Node s = q.top(); q.pop();
		int pos = s.pos;
		for (int i = 0;i < graph[pos].size();i++) {
			int to = graph[pos][i].to;
			int cost = graph[pos][i].cost;
			if (d[pos] + cost < d[to]) {
				d[to] = d[pos] + cost;
				q.push(Node(to, d[to]));
			}

		}
	}
	cout << d[TO] << endl;
}
int partition(int A[],int p, int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p;j < r;j++) {
		if (x >= A[j]) {
			i = i + 1;
			swap(A[i], A[j]);
		}
	}
		swap(A[i + 1], A[r]);
		return i + 1;
}
void quicksort(int A[], int p, int r) {
	if (p < r) {
		int q = partition(A, p, r);
		quicksort(A, p, q-1);
		quicksort(A, q + 1, r);
	}
}

int getNumberOfCoin(int C[],int n,int m) {
	int T[50000];
	for (int j = 0;j <= n;j++) {
		T[j] = INF;
	}
	T[0] = 0;
	for (int i = 0;i < m;i++) {
		for (int j = 0;j <= n;j++) {
			if (j - C[i] >=0  ) {
				T[j] = min(T[j], T[j - C[i]] + 1);
			}
		}
	}
	return T[n];
}
int knapsack(int w, int n,int* v,int* ww) {
	int W[101][10001];
		for (int j = 0;j <= w;j++) {
			W[0][j] = 0;
		}
	for (int i = 0;i < n;i++) {
		for (int k = 0;k < n;k++){
			for (int j = 0;j <= w;j++) {
				if (j - ww[k] < 0) {
					W[i + 1][j] = W[i][j];
				}
				if (j - ww[i] >= 0) {
					W[i + 1][j] = max(W[i][j], W[i][j - ww[k]] + v[k]);

				}
			}
		}
	}
	return W[n][w];
}
int fib(int n) {
	vector<int> v(n+1);
	v[0] = 1;
	v[1] = 1;
	for (int i = 2;i < n+1;i++) {
		v[i] = v[i - 2] + v[i - 1];
	}
	return v[n];
}
int isPrime(int x) {
	if (x <= 1) return false;
	if (x>2 && x % 2 == 0) return false;
	for (int i = 2;i <= sqrt(x);i++) {
		if (x%i == 0) {
			return false;
		}
	}
	if (x == 2) return true;
	return true;
}
int main(){
	int n;
	vector<int> a;
	while (cin >> n) {
		a.push_back(n);
	}
	for (int j = 0;j < a.size();j++){
		int count = 0;
		for (int i = 2;i <= a[j];i++) {
			
			if (isPrime(i)) {
				count++;
			}
			
		}
		cout << count << endl;
	}
	

}

C++: #include <iostream>
#include <math.h>
using namespace std;
bool isPrime(int n) {
    bool flag = false;
    if(n % 2 == 0) {
        if(n==2){
            flag=true;
        }
    }
    else {
        for(int i=3;i<=n;i+=2) {
            if(n==i) {flag=true;break;
            }else if(n % i==0){
                flag=false;break;
            }else flag=true;
        }
    }
    return flag;
}
int main(void){
    int n=0;
    int count = 0;
    while(cin>>n) {
        count = 0;
        for(int i=2;i<=n;i++) {
            if(isPrime(i))count++;
        }
        std::cout << count << std::endl;
    }
}