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 <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int n;
bool is_prime[100000];
int prime[100000];

int main(int argc, char const* argv[])
{
	fill(is_prime, is_prime+100000, true);
	is_prime[0] = false;
	is_prime[1] = false;
	int res = 0;
	for(int i = 2; i < 100000; i++){
			if(is_prime[i]){
					res++;
					for(int j = 2; j * i < 100000; j++){
							is_prime[j * i] = false;
					}
			}
			prime[i] = res;
	}
	while(cin >> n){
			cout << prime[n] << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long double lb;

const int INF=1<<27;
const int MOD=(int)1e9+7;

int main(void)
{
	int n[30];
	bool po[1000001]={false};
	bool prime[1000001]={0};
	po[0]=true;
	po[1]=true;
	int cnt;
	while(cin>>n[cnt]) cnt++;

	int m=0;
	rep(i,cnt) m=max(n[i],m);

	for(int j=2;j<=m;j++){
		if(po[j]){
			prime[j]=prime[j-1];
			continue;
		}
		prime[j]=prime[j-1]+1;
		for(int k=j;k<=m;k++) po[k]=true;
	}

	rep(i,cnt) cout << prime[i] << endl;

        return 0;
}

C++: #include<stdio.h>

int main(void)
{
	int data=1,i,j,s[1000000],x;

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

C++: #include<iostream>
int r(int n){if(n<2)return 0;else if(n==2)return 1;if((n&1)==0)return 0;for(int i=3;i*i<=n;i+=2)if(n%i==0)return 0;return 1;}int main(){int n,s,i,p;for(;!(std::cin>>n).eof();){for(i=p=0;i++<=n;)p+=r(i);printf("%d\n",p);}}

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

bool dec(int value) {
  for (int j = 3; j <= value/2; j += 2) {
    if (value % j == 0) { return false; }
  }
  return true;
}

int main() {
  int n;
  while (cin >> n) {
    int count = 0;
    if (n >= 2) { count++; }
    for (int i = 3; i <= n; i += 2) {
      if (dec(i)) { count++; } 
    }
    cout << count << endl;
  }
  return 0;
}

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

bool isPrime(int);

int main() {
	int n, p;
	while (cin >> n) {
		p = 2;
		if (cin.eof())
			return 0;
		for (int i = 5; i <= n; i++) {
			if (isPrime(i))
				p++;
		}
		cout << p << endl;
	}
	return 0;
}

bool isPrime(int x) {
	for (int j = 5; j * j <= x; j += 2) {
		if (x % j == 0)
			return false;
	}
	return true;
}

C++: //艾氏&#31579;法
#include <iostream>
using namespace std;
#define MAX_N 999999+16

int prime[MAX_N];//保存素数
bool is_prime[MAX_N + 1];//第几个数字是不是素数
int sieve(int n){
	int p = 0;
	fill(is_prime, is_prime + n + 1, true);
	is_prime[0] = is_prime[1] = false;
	//其&#23454;可以&#20026;sqrt(n)
	for (int i = 2; i <= n; ++i){
		if (is_prime[i])
			prime[p++] = i;
			for (int j = i * i; j <= n; j += i)
				is_prime[j] = false;
	}
	return p;
}
int main(){
	
	int n;
	while (cin >> n){
		cout << sieve(n) << endl;
	}
	return 0;
}

C++: #include<stdio.h>
int main(void){
	int i,j,n;
	bool judge[1000000]={0};
	
	for(i=3; i<1000000; i++)if(i % 2 == 0)judge[i] = 1;
	
	for(i=3; i<500000; i+=2){
		if(judge[i]==0){
			for(j=i*2;j<1000000;j+=i){
				if(j % i == 0){
					judge[j]=1;
				}
			}
		}
	}
	
	for(;;){
		int count=0;
		scanf("%d",&n);
		if(n==0)break;
		for(i=3;i<=n;i+=2){
			if(judge[i]==0)count++;
		}
		printf("%d\n",count+1);
	}
	return 0;
}

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

int main() {
	vector<int> nPrimes;
	vector<bool> isPrime;
	vector<int> inputs;
	int maxN, sqrtMax, n;

	maxN = 0;
	while(scanf("%d", &n) != EOF) {
		if(n > maxN)	maxN = n;
		inputs.push_back(n);
	}

	sqrtMax = sqrt(maxN-1) + 1;

	isPrime.resize(maxN, true);
	nPrimes.resize(maxN, 0);

	isPrime[0] = false;

	for(int i=2; i<=sqrtMax; ++i) {
		if(isPrime[i-1] == false)	continue;
		for(int j=2*i; j<=maxN; j+=i) {
			isPrime[j-1] = false;
		}
	}
	for(int i=1; i<maxN; ++i) {
		if(isPrime[i])	nPrimes[i] = nPrimes[i-1] + 1;
		else	nPrimes[i] = nPrimes[i-1];
	}

	for(auto it=inputs.begin(); it!=inputs.end(); ++it) {
		printf("%d\n", nPrimes[(*it)-1]);
	}
}

C++: #include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <vector>

std::vector<std::size_t> prime_table = {2};

void make_prime_table(const std::size_t n)
{
    const std::size_t found_last_prime = prime_table.back();
    if(found_last_prime < n)
    {
        std::set<std::size_t> undefined_table;

        for(std::size_t i = found_last_prime + 1; i <= n; ++i)
        {
            undefined_table.insert(i);
        }

        const std::size_t sn = std::sqrt(n);
        for(std::size_t p = 0; ; ++p)
        {
            for(auto u = undefined_table.begin(); u != undefined_table.end();)
            {
                if(0 == *u % prime_table[p])
                {
                    u = undefined_table.erase(u);
                }
                else
                {
                    ++u;
                }
            }
            if(!undefined_table.empty() && found_last_prime <= prime_table[p])
            {
                prime_table.push_back(*undefined_table.begin());
                undefined_table.erase(undefined_table.begin());
                if(sn < prime_table.back())
                {
                    break;
                }
            }
        }
        prime_table.insert(prime_table.end(), undefined_table.begin(), undefined_table.end());
    }
}

std::vector<size_t> prime_acc = {0};

std::size_t prime_size(const std::size_t limit)
{
    if(prime_acc.size() <= limit)
    {
        make_prime_table(limit);
        auto it = prime_table.begin();
        while(prime_acc.size() <= limit)
        {
            it = std::lower_bound(it, prime_table.end(), prime_acc.size());
            if(it != prime_table.end())
            {
                prime_acc.insert(prime_acc.end(), *it - prime_acc.size(), prime_acc.back());
                prime_acc.push_back(prime_acc.back() + 1);
            }
            else
            {
                prime_acc.insert(prime_acc.end(), limit - prime_acc.size() + 1, prime_acc.back());
            }
        }
    }
    return prime_acc[limit];
}

int main()
{
    std::size_t n;

    while(std::cin >> n, !std::cin.eof())
    {
        std::cout << prime_size(n) << std::endl;
    }
}