Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	num := make([]bool, 1000000)

	for sc.Scan() {
		var nmpr int

		n, _ := strconv.Atoi(sc.Text())

		lmt := int(math.Sqrt(float64(n)))

		for i := 2; i <= lmt; i++ {
			for j := 2; i*j <= n; j++ {
				if !num[i*j] {
					num[i*j] = true
				}
			}
		}

		for t := 2; t <= n; t++ {
			if !num[t] {
				nmpr++
			}
		}

		fmt.Println(nmpr)
	}

}

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

C++: #include<stdio.h>

int main(void)
{
	int d=0,i,j,s[100000],x;

	for(i=2;i<=100000;i++)
		s[i]=1;

	while(scanf("%d",&d)!=EOF)
	{
		x=0;
	for(i=2;i<=d;i++){
	    if(s[i]==1){
		  for(j=i*2;j<=d;j+=i)
			   s[j]=0;
		}
	}
		if(d<=1){
			printf("%d\n",0);
		}
		else
		{
		for(i=2;i<=d;i++){
			x+=s[i];
		}
		printf("%d\n",x);
		}
	}
  return 0;
}