Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 0
                                }
                        }
                }
        }
}

C++: #include <bits/stdc++.h>
using namespace std;

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;

vi prime;
vector<bool> is_prime;

void sieve(number n) {
    is_prime.assign(n + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (number i = 2; i < n; ++i) {
        if (is_prime[i]) {
            prime.pb(i);
            for (number j = i + i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
}

int main() {
    int n; 
    sieve(1010101);
    while(cin >> n){
        int t = upper_bound(all(prime),n) - prime.begin();
        cout << t << endl;
    }
}

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

using namespace std;

int sosuu(int n) {
    vector< bool > prime(n + 1);
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i <= n; i++) {
        prime[i] = true;
    }

    for (int j = 2; j * j <= n; j++) {
        if (prime[j] == true) {
            for (int i = j; i <= n; i++) {
                if (i % j == 0 && i != j) {
                    prime[i] = false;
                }
            }
        }
    }
    int count = 0;
    for (int i = 0; i <= n; i++) {
        if (prime[i] == true) {
            // cout << i << " ";
            count++;
        }
    }
    // cout << endl;
    return count;
}

int main() {
    int a;
    while (!cin.eof()) {
        cin >> a;
        if (std::cin.fail()) break;
        cout << sosuu(a) << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

const int MAX = 1000100;
bool prime[MAX];

void sieve(){
	fill(prime, prime+MAX, true);
	prime[0] = prime[1] = false;

	for(int i=2; i*i < MAX; i++){
		if(!prime[i]) continue;
		for(int j=i*i; j < MAX; j += i) prime[j] = false;
	}
}


int main(){
	sieve();
	int n;
	while(cin >> n){
		int ret = 0;
		for(int i=0; i<= n; i++){
			if(prime[i]) ret++;
		}
		cout << ret << endl;
	}
}

C++: 
#include <iostream>
#include <cstdio>
using namespace std;
#define OVER_SIX_DIGITS 1000000

int prime[OVER_SIX_DIGITS];

void make_prime(void) {
    for(int r = 0; r < OVER_SIX_DIGITS; r++) prime[r] = 1;
    prime[0] = prime[1] = 0;
    
    for(int r = 2; r < OVER_SIX_DIGITS; r++) {
        if(prime[r]) {
            for(int c = 2 * r; c < OVER_SIX_DIGITS; c += r) prime[c] = 0;
        }
    }
    //累積和配列を作成
    for(int r = 1; r < OVER_SIX_DIGITS; r++) prime[r] += prime[r - 1];
}

int main(void) {
    int n;
    make_prime();
    while(cin >> n) {
        cout << prime[n] << endl;
    }
    return(0);
}

C++: 
#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;
	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;
		}
	}
	return p;
}
int main(){

	int n;
	while (cin >> n){
		cout << sieve(n) << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
const int ub=1e6;

int main(){
	vector<bool> prime(ub, true);
	vector<int> numprime(ub, 0);
	for(int i=2; i<ub; i++){
		if(prime[i]){
			numprime[i] = numprime[i-1]+1;
			for(int j=2; i*j<ub; j++){
				prime[i*j]=false;
			}
		}else{
			numprime[i] = numprime[i-1];
		}
	}
	
	int n;
	while(cin>>n){
		cout << numprime[n] << endl;
	}
	return 0;
}

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

bool IsPrime(int m){
    if(m==1){
        return(0);
    }else if(m==2){
        return(1);
    }else if(m%2==0){
        return(0);
    }else{
        for(int i=3;i*i<=m;i+=2){
            if(m%i==0)return(0);
        }
        return(1);
    }
}

int main(){
    int n;
    int r[30];
    for(int i=0;i<30;i++){
        r[i]=0;
    }
    int j=0;
    while(cin>>n){
        for(int i=1;i<=n;i++){
            if(IsPrime(i))r[j]++;
        }
        cout<<r[j]<<endl;
        j++;
    }
    return(0);
}

C++: #include<iostream>
const int MAX_N=1000000;
using namespace std;
bool value[MAX_N];
int main(){
	int n;
	while(cin>>n){
	int count=0;
	for(int i=1;i<=n;++i){
	 value[i]=true;
	}
	for(int i=2;i<=n;++i){
		if(value[i]){
		  for(int j=2;j<=n/i;++j){
		      value[j*i]=false;
		}
	}
	for(int i=2;i<=n;++i){
	   if(value[i])
		   ++count;
	}
	cout<<count<<endl;
	}
return 0;
}

C++: #include <stdio.h>
#include <vector>

int main(void){
	int n;
	while(scanf("%d",&n)!=EOF){
		int count=0;
		std::vector<int> num;
		for(int m=2;m<=n;m++){
			bool check=true;
			for(unsigned int i=0;i<num.size();i++){
				if(m!=num[i] && m%num[i]==0){
					check=false;
					break;
				}
			}
			if(check==true){
				if(num.size()>0){
					for(int i=num[num.size()-1];i<m;i++){
						if(i!=m && m%i==0){
							check=false;
							break;
						}
					}
				}
				else{
					for(int i=2;i<m;i++){
						if(i!=m && m%i==0){
							check=false;
							break;
						}
					}
				}
			}
			if(check==true){
				num.push_back(m);
				count++;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define N 1000000
vi s(N + 1, 1);
void eli(int p)
{
    for (int i = p + p; i <= N; i = i + p)
    {
        s[i] = 0;
    }
}
void eratos(){
    s[0] = s[1] = 0;
    rep(i, N + 1)
    {
        if (s[i] == 1)
        {
            eli(i);
        }
    }
}
int main(){
    eratos();
    vi sum(N + 1, 0);
    rep(i,N){
        sum[i + 1] = sum[i] + s[i + 1];
    }
    int n;
    while(cin>>n){
        cout << sum[n] << endl;
    }

    return 0;
}