Go: package main

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

func main() {
	b2i := func(b bool) int {
		if b {
			return 1
		}
		return 0
	}

	prime := func(n int) []int {
		ans := make([]int, n+1)
		for i := 2; i <= n; i++ {
			b := ans[i] == 0
			ans[i] = ans[i-1] + b2i(b)
			if b {
				for j := i * 2; j <= n; j += i {
					ans[j] = 1
				}
			}
		}
		return ans
	}
	reader := bufio.NewScanner(os.Stdin)
	primeT:=prime(999999)
	for reader.Scan() {
		n, _ := strconv.Atoi(reader.Text())
		fmt.Println(primeT[n])
	}
}

C++: #include<stdio.h>

int main(void)
{
	int data,i,j,k=0,l=0,kai=0,s[1000000]={0};

	while(scanf("%d",&data) != EOF)
	{
		if(data<=1)
		   kai=0;
		else
		{
			for(i=2;i<=data;i++)s[i]=i;

		    i=2;
			while(i*2<data)
			{
			  if(s[i] != 0)
			  {  
				 j=2;
				while(j*i<=data)
				{
					s[j*i]=0;
					j+=1;
				}
			  }
			  i+=1;
			}

			
			for(i=2;i<=data;i++)
			{	
				if(s[i]!=0)
				{
					kai+=1;
				}
			}
		}
		printf("%d",kai);
		kai=0;
	}

  return 0;
}

C++: //	created : 16/03/06
// 	autor   : Rp7rf
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define INF 1e9
#define MAX 999999
bool prime[MAX];
int cnt[MAX];

void init_prime(){
	rep(i,MAX){
		prime[i] = true;
		
	}
	prime[0] = prime[1] = false;
	int c = 0;
	rep(i,MAX){
		if(prime[i]){
			for(int j = i + i ; j < MAX ; j += i){
				prime[j] = false;
			}
			c++;
		}
		cnt[i] = c;

	}
}

int main(void){
	init_prime();
	int n ;
	while(cin>>n){
		cout<<cnt[n]<<endl;
	}
}

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

int main(){
 int n,i,j,x,counter;
 cin >> n;
 counter = 0;
 
 for (i = 1; i <= n; i++) {
   x = 0;
   
   for (j = 1; j <= i; j++) {
     if (i % j == 0) x++;
   }
   
   if (x == 2) counter++;
 }
 
 cout << counter << endl;
 
 return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;
#define NUM 1000000

int main(){
	long long int n;
	while(cin>>n){
		long long int i,j,a=0,p[NUM];
		for(i=0;i<NUM;i++)p[i]=0;
		for(i=2;i<1001;i++){
			if(p[i]==0){
				p[i]=2;
				for(j=2;j<=NUM/i;j++){
					p[j]=1;
				}
			}
		}
		for(i=2;i<=n;i++){
			if(p[i]==2){
				a++;
			}
		}
		cout<<a<<endl;
	}
    return 0;
}

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

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-10;

double zero(double d) {
    return d < EPS ? 0.0 : d;
}

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    rep(i, a.size()) os << (i ? " " : "") << a[i];
    return os << ']';
}

// to avoid error on mingw
string toString(int i) {
    stringstream ss;
    ss << i;
    return ss.str();
}

const int MOD = 1000000007;
// a^k
ll fpow(ll a, ll k, int M) {
    ll res = 1ll;
    ll x = a;
    while (k != 0) {
        if ((k & 1) == 1)
            res = (res * x) % M;
        x = (x * x) % M;
        k >>= 1;
    }
    return res;
}

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(8);
    ios_base::sync_with_stdio(false);

    const int MAX_N = 1000000;
    bool sieve[MAX_N];
    fill(sieve, sieve+MAX_N, true);
    sieve[1] = false;

    for(int i=2; i*i <= MAX_N; ++i) {
        for(int j=i*i; j < MAX_N; j += i) {
            sieve[j] = false;
        }
    }

    vi prime_num(MAX_N, 0);
    REP(i, 1, MAX_N){
        prime_num[i] = prime_num[i-1];
        if(sieve[i])
            prime_num[i]++;
    }

    int n;
    while(cin >> n) {
        cout << prime_num[n] << endl;
    }

    return 0;
}

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