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>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

bool is_prime[1000000];
int prime[1000000];

int main() {
	int n;
	rep(i, 1000000)is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	int p = 0;
	for (int i = 2; i < 1000000; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (int j = 2 * i; j < 1000000; j += i)is_prime[j] = false;
		}
	}
	while (cin >> n) {
		cout << upper_bound(prime, prime + p, n) - prime << endl;
	}
	return 0;
}

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

int main(){
	bool is_prime[1000000];

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

	for (int i = 2; i*i < 1000000; i++){
		if(is_prime[i]){
			is_prime[i] = false;
		}
	}
	int n_prime[1000000];

	int cnt = 0;
	for (int i = 0; i < 1000000; i++){
		if (is_prime[i]){
			cnt++;
		}
		n_prime[i] = cnt;
	}

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

		if (cin.eof())
			break;

		cout << n_prime[n] << endl;
	}
	return 0;
}

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

int main() {
	int n, ans; bool not_prime[1000000 + 1];
	not_prime[0] = true;
	not_prime[1] = true;
	for (int i = 2; i <= sqrt(1000000); i++) {
		if (not_prime[i] != true) {
			for (int j = i * 2; j <= 1000000; j += i) {
				not_prime[j] = true;
			}
		}
	}
	for (int i = 0; i < 1000000 + 1; i++) {
		if (not_prime[i] != true) { not_prime[i] = false; }
	}
	while (cin >> n) {
		ans = 0;
		for (int i = 2; i <= n; i++) {
			if (not_prime[i] == false) { ans++; }
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
	long n;
	cin >> n;
	//n = 1;
	long cnt = 0;
	for (long i = 0; i < n; i++){
		long m;
		cin >> m;
		//m = 4;
		bool p = 1;
		long o;
		o = sqrt(m);
		for (long j = 0; j < o; j++){
			if (j > 0 && m % (j + 1) == 0){
				p = 0;
				break;
			}
		}
		if (p == 1) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

C++: #include<stdio.h>
#include<math.h>
#define N 1000000
int main(void) {
	int prime[N] = { 0 }, sums[N] = { 0 }, n, sum = 0;
	prime[1] = 1;
	for (size_t i = 2; i <= sqrt(N); i++)
	{
		if (prime[i] == 0)
		{
			sum++;
			sums[i] = sum;
			for (size_t t = i + 1; t <= N; t++)
			{
				sums[t] = sum;
				if (t%i == 0)prime[t] = 1;
			}
		}
	}
	while (scanf("%d", &n) != EOF) {
		printf("%d\n", sums[n]);
	}
	return 0;
}

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

static const int InputMaxLen = 6;
class PrimeNumber {
public:
    void Run();

private:
    bool readData();
    bool calcPrimeNumber();
    void printData();
    bool checkDigit(int num);

private:
    std::vector<int> inputDataList;
    std::vector<int> ouotputDataList;
};

void PrimeNumber::Run()
{
    if (!readData()) {
        std::cout << "Failed read value." << std::endl;
        return;
    }
    if (!calcPrimeNumber()) {
        std::cout << "Failed calc prime number." << std::endl;
        return;
    }
    printData();
}

bool PrimeNumber::readData()
{
    int val = 0;

    while (std::cin >> val) {
        if (!checkDigit(val)) {
            return false;
        }
        inputDataList.push_back(val);
    }

    return true;
}

bool PrimeNumber::calcPrimeNumber()
{
    unsigned int val = 0;
    int cnt = 0;
    for (unsigned int i = 0; i < inputDataList.size(); ++i) {
        val = inputDataList.at(i);
        cnt = 0;
        if (!checkDigit(val)) {
            return false;
        }
        if (val >= 2) {
            cnt++;
        }
        if (val >= 3) {
            cnt++;
        }
        for (unsigned int j = 4; j <= val; ++j) {
            for (unsigned int k = 2; k <= j; ++k) {
                if (j == k) {
                    cnt++;
                }
                else if (0 == j % k) {
                    break;
                }
            }
        }
        ouotputDataList.push_back(cnt);
    }

    return true;
}

void PrimeNumber::printData()
{
    for (unsigned int i = 0; i < ouotputDataList.size(); ++i) {
        std::cout << ouotputDataList.at(i) << std::endl;
    }
}
// Check the value whether 6 digit.
bool PrimeNumber::checkDigit(int num)
{
    int cnt = 0;

    while (num > 0) {
        cnt++;
        num /= 10;
    }
    if (cnt > InputMaxLen) {
        return false;
    }
    return true;
}

int main()
{
    PrimeNumber obj;

    obj.Run();
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int tmp;
	while (cin >> tmp)
	{
		vector<int> prime;

		for (int i(2); i <= tmp; ++i)
		{
			for (vector<int>::iterator i2(prime.begin()), n2(prime.end()); i2 != n2; ++i2)
			{
				if ((i % *i2) == 0)
				{
					goto nx;
				}
			}

			prime.push_back(i);
		nx:;
		}

		cout << prime.size() << endl;
	}

	return 0;
}

C++: #include<cstdio>
#include<vector>
using namespace std;
int main(void){
	int n;
	vector<int> a;
	int c;
	a.push_back(2);
	a.push_back(3);
	for (int i = 2; i < 510000; i++){
		for (int j = 1; j < a.size(); j++){
			if (a[j] * a[j]>2*i+1){
				a.push_back(2*i+1);
				break;
			}
			if ((2*i+1)%a[j] == 0)break;
		}
	}

	while (scanf("%d", &n) != EOF){
		c = 0;
		for (int i = 0; a[i] <= n; i++)c++;
		printf("%d\n", c);
	}
	return 0;
}

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

int sosu(int num){
int i;



for(i=2;i<=sqrt((double)num);i++){
if(num%i==0)return 0;
}

if(num==4)return 0;

return 1;

}

int main(){
int n,i,count;

while(cin >> n){

for(i=2;i<=n;i++){
if(sosu(i)){ 
count++;
}
}

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


}

C++: #include<cstdio>

int main(){
	int f[1000001] = {};
	int n;

	for(int i = 2; i < 500001; i++){
		f[i * 2] = 1;
	}

	for(int i = 3; i <= 1000; i += 2){
		for(int j = 2; j * i <= 1000000; j++){
			f[i * j] = 1;
		}		
	}

	int sum;

	while(scanf("%d", &n) + 1){
		int sum = n - 1;
		for(int i = 2; i <= n; i++){
			sum -= f[i];
		}
		printf("%d\n", sum);
	}
	return 0;
}