Go: package main

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

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[n])
    }
}

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

bool prime[1000001];

void era(){
	for(int i=0;i<1000000;i++)prime[i]=1;
	prime[0]=0;
	prime[1]=0;
	for(int i=0;i<1000000;i++){
		if(prime[i]==true){
			for(int j=i*2;j<1000000;j+=i){
				prime[j]=0;
			}
		}
	}
}

int main(){
	era();
	int n,ans;
	while(cin>>n){
		ans=0;
		for(int i=0;i<n;i++){
			if(prime[i]==1)ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
	int n;
	int p[1000000] = { 1 };
	int ans[1000000] = { 0 };
	p[0] = 0;
	p[1] = 0;

	for (int i = 2; i < 1000; i++){
		if (p[i]){
			for (int j = i*i; j < 1000000; j+=i){
				p[j] = 0;
			}
		}
	}

	for (int i = 0; i < 1000000; i++){
		ans[i] += p[i];
	}

	while (cin >> n)
		cout << ans[n] << endl;

}

C++: #include <algorithm>
#include <sstream>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <string>
#include <queue>
#include <vector>
using namespace std;

bool N[1000000];

bool primeNumber(int num) {
	if (N[num]) return true;
	else if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;

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

	return N[num] = true;
}

int main()
{
	int n;
	while (cin >> n && n != EOF) {
		int cnt = 0;
		for (int i = n; i > 1; i--) {
			if (primeNumber(i)) cnt++;
		}
		cout << cnt << endl;
	}
}

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

int main(){
    int n;
    int result;
    int i, j;
    bool flug = false;

    while(cin >> n){
        for(i=3; i<n; i++){
            if(i % 2 == 0){
                continue;
            }
            for(j=3; j * j <= i; j+=2){
                if(i % j == 0){
                    flug = true;
                    break;
                }
            }
            if(!flug) result++;
            flug = false;
        }

        cout << result+1 << endl;
        result = 0;
    }

    return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
#define N 1000001
bool prime[N];
int cnt[N];
int main() {
	for (int i = 0; i < N ; i++)prime[i] = true;
	int n = sqrt(N);
	prime[0] = prime[1] = false;
	for (int i = 2; i <= n; i++) {
		if (prime[i]) {
			for (int j = i + i; j <= N; j += i)prime[j] = false;
		}
	}
	cnt[0] = cnt[1] = 0;
	for (int i = 2; i < N; i++) {
		if (prime[i])cnt[i] = cnt[i - 1] + 1;
		else cnt[i] = cnt[i - 1];
	}
	int x;
	while (cin >> x) {
		cout << cnt[x] << endl;
	}
	return 0;
}

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


int main(){
	bool work[MAX];
	int num, ans = 0;

	// 入力
	cin >> num;

	// 初期化
	for(int i = 0; i < MAX; i++){
		if(i < 2){
			work[i] = false;
		}else{
			work[i] = true;
		}
	}

	// エラトネスのふるい
	for(int i = 2; i < sqrt((double)MAX) + 1; i++){
		if(work[i] == true){
			for(int j = i * 2; j < MAX; j += i){
				work[j] = false;
			}
		}
	}

	// 計算
	for(int i = 0; i < num; i++){
		if(work[i] == true){
			ans++;
		}
	}

	// 出力
	cout << ans << endl;

	return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
    int n;
    while(cin >> n)
    {
        int cnt = 0;
        for(int i = 2; i <= n; i++)
        {
            bool is_prime = true;
            for(int j = 2; j <= i / 2; j++)
            {
                if(i % j == 0)
                {
                    is_prime = false;
                    break;
                }
            }
            if(is_prime) cnt++;
        }
        cout << cnt << endl;
    }
}

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

int main() {
	int n;
	while (std::cin >> n) {
		int a = 0;
		if (n == 0) {
			break;
		}
		for (int i = 2; i <= n; ++i) {
			bool f = true;
			for (int j = 2; j < i&&f; ++j) {
				if (i%j == 0) {
					f = false;
				}
			}
			if (i == 2) {
				++a;
			}
			else if (f) {
				++a;
			}
		}
		std::cout << a << std::endl;
	}
	return 0;
}

C++: #include <stdio.h>
const int MAX_V = 1000000; // 100???????????????????f???????¢\????°???¬?????
int prime[MAX_V+1] ,cnt[MAX_V+1] = {0};
int main(){
		int k,i,n; // 1????????f???????C0????????f????????????????????¢
	for(i = 2; i <= MAX_V; i++) {
		prime[i] = 1; // 2???????£????f????????????°??????¨
	}
	for(i = 2; i*i <= MAX_V; i++) {
		cnt[i] = cnt[i-1];
		//printf("")
		if(prime[i]) {
			for(k = 2 * i; k <= MAX_V; k += i) {
				prime[k] = 0; // ???f??????2???{???????£????{?????????f????????????????????¢
			}
			cnt[i]++;
		}
	}
	while(scanf("%d",&n) != EOF){
		printf("%d\n",cnt[n]);
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <fstream>

#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cctype>

#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>

using namespace std;

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){
    os << "{ ";
    for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
        os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", ");
    os << " }";
    return os;
}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define vv(type,w,h,init) vector<vector<type>>(h,vector<type>(w,init))
typedef vector<string> vs;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long ul;
typedef unsigned long long ull;

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define mp make_pair

string const resstr[] = {"Impossible","Possible","No","Yes"};

bool p[1000100];

void erato(){
	fill(p, p+1000100, true);
	p[0] = p[1] = false;
	
	for(int i=0; i < 1000100; i++){
		if(!p[i]) continue;
		for(int j=i+i; j < 1000100; j+=i){
			p[j] = false;
		}
	}
}

int main(){
	int n;
	erato();
	while(cin >> n){
		int count = 0;
		for(int i=0; i <= n; i++){
			if(p[i]) count++;
		}
		cout << count << endl;
	}
}

C++: #include<stdio.h>
#include<math.h>
int isprime(int x){
	int i;
	i = 3;
	while( i <= sqrt(x) ){
		if(x%i==0){
			return 0;
		}
		i = i + 2;
	}
	return 1;
}
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		int c=1;
		for(int i=3;i<=n;i+=2){
			if(isprime(i)){
				c++;
			}
		}
		printf("%d\n",c);
	}
	return 0;
}

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

const int MAX = 1000000;
int cnt[MAX];
bool isCmp[MAX] = {true};


int main() {
    ios::sync_with_stdio(false);
    int n;
    cnt[1] = 0;
    for(int i = 2; i < MAX; i++){
      if(! isCmp[i]){
        for(int j = 2; i*j < MAX; j++){
          isCmp[i*j] = true;
        }
      }
      cnt[i] = cnt[i-1] + !isCmp[i];
    }

    while(cin >> n){
      cout << cnt[n] << endl;
    }
    return 0;
}